Problem Description
Nilo and Teena are playing with each other. Nilo challenges Teena to sum the digit of a number. Help Teena to answer as quick as possible.CODING ARENA
#include <stdio.h>
int main()
{
int n,t,sum=0,rem;
scanf("%d",&n);
t=n;
while(t!=0)
{
rem=t%10;
sum=sum+rem;
t=t/10;
}
printf("%d",sum);
return 0;
}
Test Case 1
Input (stdin)300
Expected Output3
Test Case 2
Input (stdin)16789
Expected Output31
No comments:
Post a Comment