C Program to find sum of digits of given n digit number using while loop
Program:
#include <stdio.h>
int main()
{
int n, t, sum = 0, remainder;
printf("Enter an integer\n");
scanf("%d", &n);
t = n;
while (t != 0)
{
remainder = t % 10;
sum = sum + remainder;
t = t / 10;
}
printf("Sum of digits of %d = %d\n", n, sum);
return 0;
}
Output:
Flowchart:
Guest post by: Ruturaj Shivalkar
No comments:
Post a Comment
Feel free to ask us any question regarding this post