Computer Science, asked by moidabdul312, 4 months ago

write a program to input a number sum of all digits present in the number​

Answers

Answered by Anonymous
1

Sum of digits C program

m to calculate the sum of digits of a number, we use modulus operator (%) to extract individual digits of a number and keep on adding them.

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;

}

Attachments:
Similar questions