Ticker

6/recent/ticker-posts

sum of digits of a number Program

Find sum of digits of a number - 



#include <stdio.h>
int main()
{
  int r,n,sum=0;
  scanf("%d",&n);
  while(n>0)
  {
    r=n%10;
    n=n/10;
    sum=sum+r;
  }
  printf("%d",sum);
return 0;
}

Output -

456
15

Post a Comment

0 Comments