- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1401 Articles for C
4K+ Views
In C programming language, bubble sort is the simplest sorting technique and is also called as an exchange sort.Procedure for bubble sortCompare the first element with the remaining elements in the list and exchange(swap) them, if they are not in order.Repeat the same for other elements in the list until all the elements gets sorted.AlgorithmGiven below is an algorithm to sort a given list of numbers in an ascending order by using the bubble sort technique −Step 1 − StartStep 2 − Take list(array), numStep 3 − readlist(list, num)Step 4 − printlist(list, num)Step 5 − bub_sort(list, num)Step 6 − printlist(list, num)readlist ... Read More
2K+ Views
Given below is an algorithm to convert roman numbers to decimal numbers in C language −AlgorithmStep 1 − StartStep 2 − Read the roman numeral at runtimeStep 3 − length: = strlen(roman)Step 4 − for i = 0 to length-1 do Step 4.1 − switch(roman[i]) Step 4.1.1 − case ‘m’: Step 4.1.2 − case ‘M’: Step 4.1.2.1 − d[i]: =1000 Step 4.1.3 − case ‘d’: Step 4.1.4 − case ‘D’: ... Read More
145 Views
Problem Statement Given a binary number, you have to write a C program to find 2'c complements for given binary number. Consider an example given below −ExampleThe input is as follows:Enter a binary number:10010001The output is as follows:1's complement of 10010001 is 011011102's complement of 10010001 is 01101111AlgorithmRefer an algorithm to find 2’c complements for a given binary number.Step 1 − Start.Step 2 − Read the binary number at runtime.Step 3 − Copy the binary number to strdp.Step 4 − len: = strlen(str)Step 5 − For i = 0 to len-1 do Step 5.1 − if str[i] == ‘1’ ... Read More
1K+ Views
ProblemWrite a program to read two numbers, x and n, and then compute the sum of the geometric progression.1+x+x2+x3+x4+……….+xnAnd then, print x, n and sum.SolutionThe solution to compute the geometric progression in C programming language is given below −AlgorithmRefer an algorithm to compute the geometric progression.Step 1 − StartStep 2 − RepeatStep 3 − Read values for x and n at runtimeStep 4 − If n > 0 then Step 4.1: for i = 0 to n do Step 4.1.1: sum = sum +pow(x, i) Step 4.1.2: i = i+1 Step 4.2: print x, ... Read More
4K+ Views
ProblemWrite the user functions to Delete N – Characters from Position in a given string. Here, the string is given by the user at runtime.SolutionThe solution to delete n characters in a given string is as follows −AlgorithmRefer an algorithm to delete n characters in a given string.Step 1 − StartStep 2 − Read string at runtimeStep 3 − Read position from where we need to delete the charactersStep 4 − Read n, number of characters to delete from that positionStep 5 − Call the function deletestr(str, p, n) jump to step 7Step 6 − StopStep 7 − Called function deletestr(str, ... Read More
6K+ Views
ProblemFind the greatest common divisor (GCD) for the given two numbers by using the non-recursive function.SolutionIt is explained below how to find the greatest common divisor (GCD) for the given two numbers by using the non-recursive function.AlgorithmRefer an algorithm given below to find the greatest common divisor (GCD) for the given two numbers by using the non-recursive function.Step 1 − StartStep 2 − Read the integers a and bStep 3 − Call the function G=GCD(a, b) step 6Step 4 − Print G valueStep 5 − StopStep 6 − Called function: GCD(a, b)a. Initialize the i=1, j, remainder b. Remainder=i-(i/j*j) c. ... Read More
22K+ Views
ProblemFind the greatest common divisor (GCD) for the given two numbers by using the recursive function in C programming language.SolutionThe solution to find the greatest common divisor (GCD) for the given two numbers by using the recursive function is as follows −AlgorithmRefer an algorithm given below to find the greatest common divisor (GCD) for the given two numbers by using the recursive function.Step 1 − Define the recursive function.Step 2 − Read the two integers a and b.Step 3 − Call recursive function.a. if i>j b. then return the function with parameters i, j c. if i==0 d. then return ... Read More
674 Views
ProblemThe program to calculate the sum of the following expressionSum=1-n^2/2!+n^4/4!-n^6/6!+n^8/8!-n^10/10!User has to enter the value of n at runtime to calculate the sum of the series by using the predefined function power present in math.h library function.SolutionIt is explained below how to calculate sum of series using predefined function.AlgorithmRefer an algorithm given below to calculate sum of series by using the predefined function.Step 1 − Read the num valueStep 2 − Initialize fact = 1, sum = 1 and n =5Step 3 − for i= 1 to n a. compute fact= fact*i b. if i %2 = 0 c. ... Read More
64K+ Views
ProblemWrite a C program to display all the prime numbers between 1 and n is a value given by the user at run time.SolutionC program to display all the prime numbers between 1 and n is a value given by the user at run time is explained below −AlgorithmGiven below is an algorithm to display all the prime numbers between 1 and n is a value given by the user at run time.Step 1 − Read n value.Step 2 − Initialize count = 0Step 3 − for i = 2 to n a. for j = 1 to i b. ... Read More
1K+ Views
A function is a self-contained block that carries out a specific well-defined task.Types of functionsFunctions are broadly classified into two types which are as follows −Predefined functionsUser defined functionsCommunications among functionsFunctions communicate among themselves by using arguments and return value.Farm of ‘C’ function for return-datatype function name (argument list) is as follows −{ local variable declarations; executable statements(s); return (expression); }For Example, void mul (int x, int y).{ int p; p=x*y; printf(“product = %d”, p); }Prototype functionsThese functions can be done in two ways as explained below −Create a copy of the function declaration ... Read More