+ 1
After inserting massive program exits. What's wrong here
#include <iostream> using namespace std; int main() { int n,i,j; double y[50],x[50]; cout <<"n="; cin >> n; for(i = 0; i < n; i++) { cout<<"x["<<i+1<<"]"<<endl; cin >> x[i]; } j = -1; for(i = 0; i <j; i++) { if(x[i]!=0) { j++; y[i] = x[i]; } } if(j != -1){ for (i = 0; i <j; i++) { cout<<"y["<<i+1<<"]="<<y[i]<<endl; } } }
2 Réponses
+ 2
i). when you run the code in sololearn app, you need to provide exact 6 inputs at the beginning, i hope you're doing that right.
ii). in the second for loop, value of 'i' is 0, and 'j' is -1, so it'll never enters the loop, so value of 'j' will never increment and results in the last if condition will be false everytime because 'j' is still -1.
+ 1
Thanks))