program runs correctly on CB IDE but error occur on submitting the challenge.
[Challenge name: SIMPLE INPUT]
#include
using namespace std;
int main() {
int p,i,n,s=0,a[100];
cin>>n;
for(i=0;i<n;i++){
cin>>a[i];
}
for(i=0;i<n;i++){
s+=a[i];
if(s<0){
p=i;
break;
}
}
for(i=0;i<p;i++){
cout<<a[i]<<endl;
}
return 0;
}
Error occur on submitting the challenge
Hi @alok.maurya
In this question you are not given any n. You need to take input from user and print it till sum < 0.
Here is the correct way to approach this ques :
1 Like
#include
using namespace std;
int main() {
int p,i,n,s=0,a[1000];
cin>>n;
for(i=0;i<n;i++){
cin>>a[i];
}
for(i=0;i<n;i++){
s+=a[i];
if(s<0){
p=i;
break;
}
}
for(i=0;i<p;i++){
cout<<a[i]<<endl;
}
return 0;
}
Hi @alok.maurya
In this question you are not given any n. You need to take input from user and print it till sum < 0. I have already shared the code with you.
Sending it again. Please have a look at it and tell if you dont understand any part.