Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- string str;
- int a,b,c;
- int esum = 0, osum = 0;
- cin>>str;
- c=str.size();
- int arr[c];
- b=0;
- while(b!=c)
- {
- arr[b]=str[b]-'0' ;//the subtraction of ‘0’ is essential,thats what converts it to a number
- if(b % 2 == 0){
- esum += arr[b];
- }else{
- osum += arr[b];
- }
- b++;
- }
- // The entire array
- for(int i = 0; i<b; i++){
- cout<<arr[i]<<endl;
- }
- // The difference
- cout<<esum - osum;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement