int i,a[11]; for(i=0;i<10;i++) { scanf("%d",&a[i]); printf("\n"); } for(i=0;i<10;i++) { if(a[i]!=42) printf("%d\n",a[i]); else break; }
return 0;
Any help on how to edit this code and submit is appreciated
Well, you can not be sure that your array is large enough. So you should not store the numbers in an arrray at all, just read and print one number after the other an brek when you find a 42.
As said before, you can't know how many numbers you are going to read, so you should just read a number and print it until you find the number 42. Example:do{cin >> N;if(N!=42)cout << N << endl;}while(N!=42);
do{
cin >> N;
if(N!=42)
cout << N << endl;
}while(N!=42);
Thank you. It got accepted. I just increased the size of my array. If i print out as soon as i scan the number wouldn't that be wrong since the output required is directly after inputting all numbers??
For the judge program stdin and stdout are two different, seperate devices. It is similar to running your program with "piping" a input file into your program and redirecting your output to another file.
It is only your console where input and output appear to be mixed. And it is usually a good idea not to collect all input data in an array because of memory consumption issues.