C Program to find Sum of Digits of a given number
#include <stdio.h>
int main()
{
int n,rem,sum=0;
printf("Enter a number: ");
scanf("%d", &n);
int temp=n;
while (n>0) {
rem=n%10;
n=n/10;
sum = sum+rem;
}
printf("\nSum of digits of %d is %d",temp,sum);
return 0;
}
OUTPUT:
Comments
Post a Comment