0
help me this code gives runtime NZEC error.
#include <iostream> #include<vector> using namespace std; int main() { int n,q,l,m,o,sum; cin >>n; cin>>q; vector <int>v(n,0); for(int i=0;i<n;i++) { cin>>v[i]; } for(int i=0;i<q;i++) { cin>>l>>m>>o; if(l==1&&m<n) { v[m]=o; } if(l==2&&m<n&&o<n) { sum=0; for(int j=m;j<=n;j++) { sum=sum+v[j]; } cout<<sum<<endl; } else//if i remove this else statement it works fine otherwise it gives runtime error NZEC return -1; } }
8 ответов
+ 5
+ 4
Your input line of '1 0 3' for l m o in first set of values goes to the return statement. You are missing an else. Make:
if(l==2&&m<n&&o<n)
this:
else if(l==2&&m<n&&o<n)
Therefore, that set is processed by:
if(l==1&&m<n)
only and not the return afterwards.
+ 2
Need to know your inputs to help fully. Your statement of removing the else, does that include the return? Where are you running it? A return of non-zero on some systems will cause an error message.
+ 1
What inputs did you use? Did you remove the return statement?
+ 1
oh yes ,thank u sir for helping me
0
sir I am running on online website.
and I realise that outer for loop is running only once but in input there are more number that causes that error.if I am wrong correct me.
0
input
5
5
2
3
4
8
9
1
0
3
2
0
1
2
0
4
1
2
5
2
0
3
0
yes sir I have to remove else statement.