Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Add digits of number in C

Program add digits of a number - % operator which is used to add the each and every digits of a number.
#include <stdio.h>
 
int main()
{
   int no, sum = 0, remainder;
 
   printf("Enter an integer value\n");
   scanf("%d",&n);
 
   while(no != 0)
   {
      remainder = no % 10;
      sum = sum + remainder;
      no = no/ 10;
   }
 
   printf("Sum of digits of given number = %d\n",sum);
 
   return 0;
}