Advertisement
silentkiler029

sum of product using string

Jun 28th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6.     char num[25];
  7.     scanf("%s", num);
  8.  
  9.     int q, r, sum = 0;
  10.     int len = strlen(num);
  11.     int i;
  12.  
  13.     for(i = 0; i < len; i++) {
  14.         sum += num[i] - '0';
  15.     }
  16.  
  17.     printf("%d\n", sum);
  18.  
  19.  
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement