Sponsor

C Programming Tutorial #8,Add digits of number in c program

C program to add digits of a number: Here we are using modulus operator(%) to extract individual digits of number and adding them.

C programming code

#include <stdio.h>
 
int main()
{
   int n, t, sum = 0, remainder;
 
   printf("Enter an integer\n");
   scanf("%d", &n);
 
   t = n;
 
   while (t != 0)
   {
      remainder = t % 10;
      sum       = sum + remainder;
      t         = t / 10;
   }
 
   printf("Sum of digits of %d = %d\n", n, sum);
 
   return 0;
}

Share on Google Plus

About Unknown

We bring you the latest breaking news that are happening around the world. For daily news, celebrity gossips, scoops, scandals, sports news, crime news and many more, don't forget us to visit ... www.satyaaawaz.com.
    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment