You are viewing a single comment's thread. Return to all comments →
using namespace std;
int main() { int n=0,m=0; int t=0,l=0,r=0,x=0,sum=0; cin>>n>>m; int arr[n];
for(int i=0;i<n;i++) { cin>>arr[n]; } while(m--) { cin>>t>>l>>r; sum=0,x=0; if(t==1) { for(int j=l-1;j<=r-1;j+=2) { x = arr[j]; arr[j] = arr[j+1]; arr[j+1] = x; } } else if(t==2) { sum = 0; for(int k=l-1;k<=r-1;k++) { sum+=arr[k]; } cout<<sum<<endl; Can anyone explain the error in this code } } return 0;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Swaps and Sum
You are viewing a single comment's thread. Return to all comments →
include
include
using namespace std;
int main() { int n=0,m=0; int t=0,l=0,r=0,x=0,sum=0; cin>>n>>m; int arr[n];
}