C Program to find the sum of digits of a number..

#include<stdio.h>

int sumofdigits(int n)
{
 int sum=0;
 while(n!=0)
 {
  sum+=(n%10);
  n/=10;
 }
 return sum;
}

void main()
{
 int n;
 printf("\nEnter any number..");
 scanf("%d",&n);
 printf("\nThe sum of the digits of the number is..%d",sumofdigits(n));
}

No comments:

Post a comment