Q:

C PROGRAM TO SUM UP ALL INDIVIDUAL DIGITS OF A GIVEN NUMBER:

0

C PROGRAM TO SUM UP ALL INDIVIDUAL DIGITS OF A GIVEN NUMBER:

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
 
int main()
 
{
 
   int n, sum = 0, rem; 
 
   printf("Please enter an integer\n");
 
   scanf("%d",&n);
 
 
 
   while(n != 0)
 
   {
 
      rem = n % 10;
 
      sum = sum + rem;
 
      n = n / 10;
 
   }
 
   printf("Sum of all individual digits of an entered number is %d\n",sum);
 
   return 0;
 
}

output:

Please enter an integer

 3

Sum of all individual digits of an entered number is 3

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now