Sum of Digits of a Five Digit Number Discussions | C | HackerRank
We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
int main() {
int n;
int a,b,c,d,e;
scanf("%d", &n);
//Complete the code to calculate the sum of the five digits on n.
a=n%10;
b=((n%100)-a)/10;
c=((n%1000)-(n%100))/100;
d=((n%10000)-(n%1000))/1000;
e=(n-(n%10000))/10000;
printf("%d",a+b+c+d+e);
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sum of Digits of a Five Digit Number
You are viewing a single comment's thread. Return to all comments →
include
int main() { int n; int a,b,c,d,e; scanf("%d", &n); //Complete the code to calculate the sum of the five digits on n. a=n%10; b=((n%100)-a)/10; c=((n%1000)-(n%100))/100; d=((n%10000)-(n%1000))/1000; e=(n-(n%10000))/10000; printf("%d",a+b+c+d+e); return 0; }