C Program for Sum of Individual digits of a Positive Integer

Estudies4you

C Code for Sum of Individual digits of a Positive Integer

1 #include<stdio.h>
2 #include<conio.h>
3 #include<math.h>
4 void main ()
5 {
6 int number = 0, digit = 0, sumOfDigits = 0;
7 clrscr();
8 printf("Enter any number\n ");
9 scanf("%d", &number);
10 while (number != 0)
11 {
12 digit = number % 10;
13 sumOfDigits = sumOfDigits + digit;
14 number = number / 10;
15 }
16 printf ("Sum_of_individual digits of a given_number is %d", sumOfDigits);
17 getch();
18 }
Output:
1 Enter any number
2 1234
3 Sum_of_individual_digits of a given_number is 10

Click Here to Download C Programming Lab Experiments

To Top