Found 1439 Questions for C

What are printf conversion characters and their types?

Bhanu Priya
Updated on 01-Sep-2021 12:48:48
The use of printf is to print out a string with no blank fields to be filled.For example, printf ("An ordinary string.."); printf ("Testing 1, 2, 3...");The next simplest case that has been used before now is to print out a single integer number.int number = 48; printf ("%d", number);The two can be combined as shown below −int number = 48; printf ("Some number = %d", number);The result of this last example is to print out the following on the screen −Some number = 48Here is a list of the different letters for printf −d − signed denary integeru − ... Read More

C program to convert decimal fraction to binary fraction

Bhanu Priya
Updated on 01-Sep-2021 12:46:02
Consider the examples given below to understand how to convert a decimal fraction to binary fraction in C programming language.Example 1 − Conversions of 25 to binary.Step 1 − 25 / 2 Rem : 1 , Quo : 12Step 2 − 12 / 2 Rem : 0 , Quo : 6Step 3 − 6 / 2 Rem : 0 , Quo: 3Step 4 − 3 / 2 Rem : 1 , Quo: 1Step 5 − 1 / 2 Rem : 1 , Quo: 0So equivalent binary number is: 11001Example 2 − Conversions of 0.7 to binary.Step 1 − 0.7 * ... Read More

C program to implement Euclid’ s algorithm

Bhanu Priya
Updated on 01-Sep-2021 12:42:54
ProblemImplement Euclid’ s algorithm to find the greatest common divisor (GCD) and least common multiple (LCM) of two integers and to output the results along with the given integers.SolutionThe solution to implement Euclid’ s algorithm to find the greatest common divisor (GCD) and least common multiple (LCM) of two integers is as follows −The logic used to find GCD and LCM is as follows −if(firstno*secondno!=0){    gcd=gcd_rec(firstno, secondno);    printf("The GCD of %d and %d is %d", firstno, secondno, gcd);    printf("The LCM of %d and %d is %d", firstno, secondno, (firstno*secondno)/gcd); }The called function is as follows −int gcd_rec(int ... Read More

What are C operators and Punctuators?

Bhanu Priya
Updated on 01-Sep-2021 12:39:56
An operator is used to describe an operation applied to one or several objects. It is mainly meaningful in expressions, but also in declarations. It is generally a short sequence using non-alphanumeric characters.A punctuator is used to separate or terminate a list of elements.C operators and punctuators are as follows −...   &&  -=  >=   ~   +   ;  ] >   %   ,   <  ^ >>=   *=  /=  ^=   &   -   =  { !=    ++    | %=    +=  

C program to compute the polynomial regression algorithm

Bhanu Priya
Updated on 01-Sep-2021 12:37:39
Regression is a predictive modelling technique that investigates the relationship between a dependent and non-dependent variable.Polynomial regressionIt is a form of regression analysis that shows the relationship between an independent variable x and the dependent variable y that is modelled a nth degree polynomial in x.ExampleFollowing is the C program to compute the polynomial regression algorithm −#include #include #include main(){    int i,j,k,m,n;    float x[20],y[20],u,a[10],c[20][20],power,r;    printf("enter m,n:");    scanf("%d%d",&m,&n);    for(i=1;i

C program to compute linear regression

Bhanu Priya
Updated on 31-Aug-2021 13:57:57
ProblemWrite a program to implement linear regression algorithm.User has to enter total number of values.SolutionThe solution to compute the linear regression in C programming language is as follows −Linear regression finds the relationship between two variables by connecting a linear equation to the observed data. One variable is to be an explanatory variable, and the other is a dependent variable.The logic with regards to linear regression is explained below −for(i=0;i

C program to sort a given list of numbers in ascending order using Bubble sort

Bhanu Priya
Updated on 01-Sep-2021 08:37:58
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

C program to convert roman numbers to decimal numbers

Bhanu Priya
Updated on 01-Sep-2021 09:04:49
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

Find 2’c complements for given binary number using C language

Bhanu Priya
Updated on 01-Sep-2021 09:00:14
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’ then        Step 5.1.1 − str[i] == ‘0’     Step 5.2 − Else        Step 5.2.1 − ... Read More

C program to compute geometric progression

Bhanu Priya
Updated on 01-Sep-2021 09:06:43
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
Previous 1 ... 4 5 6 7 8 9 10 ... 144 Next
Advertisements