Write a program to find sum of digits in C

#include<stdio.h>
#include<conio.h>
void main()
{
int rem,sum,n;
sum=0;

printf("\n\n Enter Any number: ");
scanf("%d",n);

while(n>0)
{
rem=n%10;
sum=sum+rem;
n=n/10;
}

printf("\n\nThe sum of the number is=%d",sum);
getch();

}

Previous
Next Post »