Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int LenString(char* str)
- {
- int i = 0;
- while (str[i]) i++;
- return i - 1;
- }
- int main() {
- char a[80];
- gets_s(a);
- int count = 1;
- int sum = 0;
- for (int i = 0; i <= LenString(a); i++) {
- 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') {
- ++count;
- if (count % 2 == 0) {
- sum += (a[i]-48) ;
- }
- else sum -= (a[i]-48) ;
- }
- }
- cout<<"sum = " << sum;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement