This problem will calculate the sum of all digit in the value give by user. #include<stdio.h> void main() { long long no,temp; int rem,sum=0; printf("\n\tEnter 5 to 6 digit number "); scanf("%lld",&no); temp=no; //printf("no=%ld",no); do { while(temp!=0) { rem=temp%10; //// printf("rem=%d\n",rem); sum=sum+rem; temp=temp/10; } //printf("\nsum %d",sum); temp=sum; sum=0; // printf("\ntemp=%ld",(temp/10)); }while((temp/10)!=0); printf("\n\t_____________________________________"); printf("\n\tSum %d\n",temp); }
-
-
The Detailed Problem Is Describe Below. A pharmaceutical company provides solution to complete a chemical process. Time and resources taken by chemical process depends on set of chemical compounds as an input conditions. Company charges on the following basis: • If number of hours required to complete chemical process is less or equal to 48 then rates are rupees 2k per hour. • If number of hours are more than 48 and less than 240, then the rates are up to 48 hours as serial number 1. For all the remaining rate is fixed at rupees 4k per hours. • …
-
This Program calculate the average of five numbers. This gives basic working of C Program. #include<stdio.h> void main() { int no1,no2,no3,no4,no5,sum; float avg; printf("\n\tEnter First Number "); scanf("%d",&no1); printf("\n\tEnter Second Number "); scanf("%d",&no2); printf("\n\tEnter Third Number "); scanf("%d",&no3); printf("\n\tEnter Fourth Number "); scanf("%d",&no4); printf("\n\tEnter Fifth Number "); scanf("%d",&no5); sum=no1+no2+no3+no4+no5; avg=sum/5; printf("\n\t_____________________________________________"); printf("\n\n\tSum Of Above Number Is %d",sum); printf("\n\tAverage Of Above Five Numbers Is %f\n\n",avg); }
-
This Program will give basic data type of c and perform sum of this three number. #include<stdio.h> void main() { int no1,no2,no3,sum; printf("\n\tEnter First Number "); scanf("%d",&no1); printf("\n\tEnter Second Number "); scanf("%d",&no2); printf("\n\tEnter Third Number "); scanf("%d",&no3); sum=no1+no2+no3; printf("\n\t_____________________________________________"); printf("\n\n\tSum Of %d, %d And %d Is %d\n\n",no1,no2,no2,sum); }
-
#include <math.h> #include <stdio.h> void main() { double a, b, c, d, root1, root2, realPart, imagPart; printf("Enter coefficients a, b and c: "); scanf("%lf %lf %lf", &a, &b, &c); d = b * b - 4 * a * c; if (d > 0) { root1 = (-b + sqrt(d)) / (2 * a); root2 = (-b - sqrt(d)) / (2 * a); printf("root1 = %.2lf and root2 = %.2lf", root1, root2); } else if (d == 0) { root1 = root2 = -b / (2 * a); printf("root1 = root2 = %.2lf;", root1); } else { realPart = -b…
-
As discussed before, loop contains three part Intialization Condition Checking Incrementation Or Decrementation do…while loop is also called exit control loop, it means that the statement of loop are always executed once even if the condition is false. In this while is ended by semicolon(;). Syntax variable=0; do { //statement variable++; or variable--; //increment or decrement }while(condition); Example is given below #include<stdio.h> #include<conio.h> void main() { int i = 10; // declaration and initialization at the same time clrscr(); do // do contains the actual code and the updation { printf("i = %d\n",i); i = i-1; // updation }while(i >…
-
As we discussed before the loop have three parts. Initialization Condition Checking Increment Or Decrement Part while loop is known as entry control loop, in this if the condition is true then the statement inside loop will be executed. Syntax variable=0; while(condition) { code statement variable++; or variable--; //increment or decrement part } Example is below #include<stdio.h> #include<conio.h> void main() { int i = 0; // declaration and initialization at the same time clrscr(); printf("\nPrinting numbers using while loop from 0 to 9\n\n"); /* while i is less than 10 */ while(i<10) { printf("%d\n",i); i++; // same as i=i+1; }…
-
for loop consists of three parts in a sequence. Initialization: Use to initialize the loop variable. Condition: It is checked after each iteration as an entry point to the loop. Increment or Decrement: Incrementing or Decrementing the loop variable to eventually terminate the loop not satisfying the loop condition. Remember that the loop condition checks the conditional statement before it loops again. Syntax: for(initialization, condition, incrementation or decrementation) { code statements; } Example is give below #include<stdio.h> #include<conio.h> void main() { //Always declare the variables before using them int i = 0; // declaration and initialization at the same time…
-
Some important points to be note about Global variable declaration are: It can be used anywhere within the program. Unlike local variables that can be used within the scope of a particular function. & is used to assign the input value to the variable and store it at that particular location. %0nd is used to represent numbers in n digit format with leading 0’s. #include<stdio.h> #include<conio.h> int a,b; void main() { clrscr(); printf("Enter the two values to find the greatest and smallest number: \n"); scanf("%d%d", &a, &b); if(a == b) printf("\n\nBoth are equal"); else if(a < b) { printf("\n\nThe largest…
-
Swapping means change the value of two variables with one another. There is basically four ways to perform swapping that are listed below. Using Temporary Variable Without Using Temporary Variable Using Bitwise Operator Using Multiplication And Division Using Temporary Variable In this, the anothe temporary variable is used. The value of first variable is assign to temporary variable. Then the value of second variable is assign to first and value of temporary variable is assign to second variable. #include<stdio.h> #include<conio.h> void main() { int x = 10, y = 15, temp; clrscr(); temp = x; x = y; y =…