34. WRITE A C PROGRAM FOR SUM OF THE INDIVIDUAL DIGITS I.E, ADDING ALL THE DIGITS OF A NUMBER.

/*C program for Sum of the individual digits i.e, adding all the digits of a number.*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main ()
{
int number = 0, digit = 0, sumOfDigits = 0;
clrscr();
printf("Enter any number\n ");
scanf("%d", &number);
while (number != 0)
{
digit = number % 10;
sumOfDigits = sumOfDigits + digit;
number = number / 10;
}
printf ("Sum of individual digits of a given number is %d", sumOfDigits);
getch();
}

output

Enter any number
1234
Sum of individual digits of a given number is 10

Comments