Sum of digits of 1234 = 1 + 2 + 3 + 4 = 10
Code
#include<stdio.h>
int main()
{
int sum=0,rem,no;
printf("Enter a number ");
scanf("%d",&no);
while(no != 0)
{
rem = no % 10;
sum = sum + rem;
no = no/10;
}
printf("\nSum of the digits = %d",sum);
return 0;
}
No comments:
Post a Comment