Program to accept a number and print sum of its digits.| Using C language| C Program series 19|
👨💻Program to accept a number and print the sum of its digits.
Code:
//Program to accept a number and print the sum of its digits.
#include<stdio.h>
main()
{
printf("Program to accept a number and print sum of its digits.\n\n");
int n,r,sum=0;
printf("Enter the number:");
scanf("%d",&n);
while(n>0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
printf("The sum of its digits is %d",sum);
}
Output:
Comments
Post a Comment