Advertisement
silentkiler029

sum of product mod plus function

Jun 28th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. long long SumOfProduct(long long n)
  4. {
  5.     long long r, q = n, s = 0;
  6.     while(q > 0) {
  7.         r = q % 10;
  8.         s += r;
  9.         q /= 10;
  10.     }
  11.     return s;
  12. }
  13.  
  14. int main()
  15. {
  16.     long long x; // as x <= 10^19
  17.     scanf("%lld", &x);
  18.  
  19.     long long sum;
  20.  
  21.     sum = SumOfProduct(x);
  22.  
  23.     printf("%lld\n", sum);
  24.  
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement