If a five digit number is input through the keyboard the keyboard ,write a program to calculate the sum of its digits.
/* program for sum of 5 digit Enter by the user */
#include <stdio.h>
int main()
{
int sum=0, num ,i;
printf("Enter the 5 digit number:");
scanf("%d", &num);
for(i=0;i<5;i++)//by using for loop
{
sum=sum+num%10;
num=num/10;
}
printf("The sum of the number Enter by the user is %d", sum);
return 0;
}
//output
Enter the 5 digit number:12345
The sum of the number Enter by the user is 15
Comments
Post a Comment