Add digits of number in c program C Programming Friday, May 15, 2015 Reading Add Comment adddigit.c #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 Enter an integer 12345 Sum of digits of 12345 = 15 C Programming C Programs Share: Facebook Twitter Google Plus Pinterest Related Articles
0 comments:
Post a Comment