Program In C to print the sum of digits of any number

#include<stdio.h>
#include<conio.h>

int main()
{

int n, sum = 0, rem;
printf(“Enter the number : “);
scanf(“%d “, &n);
while (n>0)
{
rem = n % 10;
sum = sum + rem;
n = n / 10;
}

printf(“Sum of digits = %d\n”, sum);

return 0;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *