This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Author : Md.Mehadi Hasan Menon. | |
* Problem : 11332 - Summing Digits. | |
* Satus : Accepted. | |
* Date : 10.10.2014. | |
**/ | |
#include <stdio.h> | |
int digitSum(long long int a); | |
int main() | |
{ | |
long long int n; | |
int ans; | |
while(scanf("%lld", &n) == 1 && n != 0) | |
{ | |
if(n < 10) | |
printf("%lld\n", n); | |
else | |
{ | |
ans = digitSum(n); | |
while(ans >= 10) | |
{ | |
ans = digitSum(ans); | |
} | |
printf("%d\n", ans); | |
} | |
} | |
return 0; | |
} | |
int digitSum(long long int a) | |
{ | |
int sum; | |
sum = 0; | |
while(a != 0) | |
{ | |
sum = sum + a % 10; | |
a = a / 10; | |
} | |
return sum; | |
} |
Comments
Post a Comment