0
help me in this code.Error is in else statement
#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; } }
20 Réponses
+ 1
output ka chod return -1 for loop(i=0;i<q..) k ander h, to for loop ek hi bar chalega fir band
input 2 dega to second for loop(j=m; j<=n...) chalega fir band
ab tuje krna kya bata de
+ 1
bhai tere program me hamesha else chelaga
tera return bade wale for loop k andr h to program ek hi bar chalega
else
break;
try kr. tab jake kuch hoga, return nikal de
+ 1
ok samaj gaya thanks
0
so where is the else part??
0
in last statement I have write comment there
0
if u want input I can give u
0
i meant the statement inside the else block
0
it is return -1,am i have done wrong?
0
you just left it empty
0
no there is statement return -1see c
0
well then its working fine
https://code.sololearn.com/cB5X7R6f8hpb/?ref=app
0
it is giving runtime error nzec and giving wrong output
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
output should be 6
27
19
0
naa ho payega tere se rahne de
0
cout<<"hi"<<"v[m]";:)
0
abe tera input hi itna khatrnak h to kaise samjega
0
code dekh le samaj jayega sab sahi hai
else hi lafda Kar Raha hai
0
Hatsy Rei can u help? please
0
yadi l=2 aur1 ke Barabar nahi hai
toh else chalega