Hello everyone, today I am going to post the flow-chart and the source code of a program that calculates the sum of digits of a number.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYkPAEhwgyjA5ojfEhl4gTm-7aL2c_tnagx8QjKi0_CyAKFb1bzJK_DidVTQLQuIaZpDp8TnvIB0kDpOZuYn2jqz9VdWnNHFRnqL-tprgUHaEzNf4OXrIgBBb5t7l2NYSTyeNaVhib3A8/s640/1.png)
/**
* Author : Berk Soysal
*/
#include <stdio.h>
void main()
{
int num, temp, digit, sum ;
printf("Enter a TWO digit number: \n");
scanf("%d", &num);
if(num > 9 && num < 100)
{
temp = num;
digit = num % 10;
num /= 10;
sum = num + digit;
printf("Given number = %d\n", temp);
printf("Sum of the digits = %d\n", sum);
}
else
{
printf("\n\n ERROR !! Please Enter a TWO Digit Number !\n\n");
}
}
Result
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFp6nkdzr_kcsFTbruKHbrf9bSEG2H5M_m4n5_7jk95T3ELCld-8HblvZEs_ZKD7SeVx-kwT57hBVilTGBGQZOtigRVod9cf-QVo9DITzENZHBuWrnDM8P_CHoEsTUjFl9Tr5GIscHqxw/s640/resultt.jpg)
Please leave a comment if you have any questions !
Keywords: CCode Snippets
Disqus Comments Loading..