**About this program:**

This program accepts a three digit number and prints the sum of its individual digits.

**Logic:**

(i) Take a three digit number from user and assign it to a variable.

Ex: n=356

(ii) Divide n by 100 and assign the quotient to a variable.

Ex: a=n/100

a=356/100

a=3 (This is the first digit)

(iii) To get the second digit –

Do n%100 and divide the result by 10 and assign the value to another variable.

Ex: b=(n%100) => b=(356%100) => b=56

b=b/10 => b=56/10 => b=5

We can do this in one line:

b=((n%100)/10) => b=((356%100)/10) => b=5

(iv) To get the third digit –

Do n%10 and assign it to another variable.

Ex: c=(n%10) => c=(356%10) => c=6

(v) Now that we have got three individual digits. Add them to get the sum.

sum=a+b+c => sum=3+5+6 => sum=14

(vi) Print the final result (sum).

### CODE:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# include <stdio.h> # include <conio.h> int main( ) { int a,b,c,n,sum; printf ("Enter a three digit number:"); scanf ("%d",&n); a=n/100; b=((n%100)/10); c=n%10; sum=a+b+c; printf("Sum of individual digits of %d is %d",n,sum); getch(); return 0; } |

**OUTPUT:**

1 2 |
Enter a three digit number: 356 Sum of individual digits of 356 is 14 |

I love the way you explain every program. Thanks ðŸ™‚

Thanks a lot ðŸ™‚ keep visiting..