About this program:
This program accepts a three digit number and prints the sum of its individual digits.
(i) Take a three digit number from user and assign it to a variable.
(ii) Divide n by 100 and assign the quotient to a variable.
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).
# include <stdio.h>
# include <conio.h>
int main( )
printf ("Enter a three digit number:");
printf("Sum of individual digits of %d is %d",n,sum);
Enter a three digit number: 356
Sum of individual digits of 356 is 14