Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int sumOfDigits(int n){
- int i, d, c, s=0;
- for (d=0; pow(10,d)<=n; d++);
- for (i=0; i<d; i++){
- c=n/pow(10,i);
- c%=10;
- s+=c;
- }
- return s;
- }
- int main(){
- int n;
- scanf("%i", &n);
- printf("The sum of its digits is %i", sumOfDigits(n));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment