Thursday, 19 December 2019

Sum of digits in C

#include<stdio.h>
#include<conio.h>
int main()
{
int n,num,r,s=0;
printf("Enter the number: ");
scanf("%d",&n);
num=n;
while(num>0)
{
r=num%10;
s=s+r;
num=num/10;
}
printf("The sum of digits is %d.",s);
getch();
return 0;
}

No comments:

Post a Comment

Convey your thoughts to authors.