Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int LenString(char* str)
  4. {
  5. int i = 0;
  6. while (str[i]) i++;
  7. return i - 1;
  8. }
  9. int main() {
  10. char a[80];
  11. gets_s(a);
  12.  
  13. int count = 1;
  14. int sum = 0;
  15. for (int i = 0; i <= LenString(a); i++) {
  16. if (a[i] == '0'|| a[i] == '1' || a[i] == '2' || a[i] == '3' || a[i] == '4' || a[i] == '5' || a[i] == '6' || a[i] == '7' || a[i] == '8' || a[i] == '9') {
  17. ++count;
  18. if (count % 2 == 0) {
  19. sum += (a[i]-48) ;
  20. }
  21. else sum -= (a[i]-48) ;
  22. }
  23. }
  24.  
  25. cout<<"sum = " << sum;
  26.  
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement