Write a program to sum of digits of a given number. e.g. If the input is 158 then output will be 14.

#include<stdio.h>
int main()
 {
  int   n, a, sum=0;
  printf( "Enter a integer number: " );
  scanf( "%d" , &n);
  while(n%10!=0)
         {
       a=n%10;
       n=n/10;
       sum=sum+a;
        }
  printf( "\nSum of the digit: %d" , sum);
      return 0;
}

No comments:

Post a Comment