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; } }

2nd Jun 2018, 10:01 AM
Bahubali
Bahubali - avatar
20 Respuestas
+ 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
2nd Jun 2018, 1:01 PM
‎ ‏‏‎Anonymous Guy
+ 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
2nd Jun 2018, 1:50 PM
‎ ‏‏‎Anonymous Guy
+ 1
ok samaj gaya thanks
2nd Jun 2018, 1:55 PM
Bahubali
Bahubali - avatar
0
so where is the else part??
2nd Jun 2018, 11:43 AM
‎ ‏‏‎Anonymous Guy
0
in last statement I have write comment there
2nd Jun 2018, 11:45 AM
Bahubali
Bahubali - avatar
0
if u want input I can give u
2nd Jun 2018, 11:49 AM
Bahubali
Bahubali - avatar
0
i meant the statement inside the else block
2nd Jun 2018, 11:50 AM
‎ ‏‏‎Anonymous Guy
0
it is return -1,am i have done wrong?
2nd Jun 2018, 11:52 AM
Bahubali
Bahubali - avatar
0
you just left it empty
2nd Jun 2018, 11:52 AM
‎ ‏‏‎Anonymous Guy
0
no there is statement return -1see c
2nd Jun 2018, 11:53 AM
Bahubali
Bahubali - avatar
2nd Jun 2018, 12:28 PM
‎ ‏‏‎Anonymous Guy
0
it is giving runtime error nzec and giving wrong output
2nd Jun 2018, 12:36 PM
Bahubali
Bahubali - avatar
0
input 5 5 2 3 4 8 9 1 0 3 2 0 1 2 0 4 1 2 5 2 0 3
2nd Jun 2018, 12:37 PM
Bahubali
Bahubali - avatar
0
output should be 6 27 19
2nd Jun 2018, 12:37 PM
Bahubali
Bahubali - avatar
0
naa ho payega tere se rahne de
2nd Jun 2018, 12:40 PM
Bahubali
Bahubali - avatar
0
cout<<"hi"<<"v[m]";:)
2nd Jun 2018, 12:41 PM
Bahubali
Bahubali - avatar
0
abe tera input hi itna khatrnak h to kaise samjega
2nd Jun 2018, 12:43 PM
‎ ‏‏‎Anonymous Guy
0
code dekh le samaj jayega sab sahi hai else hi lafda Kar Raha hai
2nd Jun 2018, 12:45 PM
Bahubali
Bahubali - avatar
0
Hatsy Rei can u help? please
2nd Jun 2018, 12:48 PM
Bahubali
Bahubali - avatar
0
yadi l=2 aur1 ke Barabar nahi hai toh else chalega
2nd Jun 2018, 1:27 PM
Bahubali
Bahubali - avatar