#include
using namespace std;
int main(){
int a[1000];
for(int i=0;i<5;i++){
cin>>a[i]; }
for(int j=0;j<5;j++){
if (a[j]==42)
break;
cout<<a[j]<<"\n"; }
return 0;
}
#include
using namespace std;
int main(){
int a[1000];
for(int i=0;i<5;i++){
cin>>a[i]; }
for(int j=0;j<5;j++){
if (a[j]==42)
break;
cout<<a[j]<<"\n"; }
return 0;
}
why you are taking input only 5 numbers?
I think you are confused after observing test cases, but actual cases differ from mentioned test cases.
So basically “Stop processing input after reading in the number 42” means that you have to take input till you don’t receive 42 as input an so you may use an infinite loop and print the number and as you’ll get 42 break the loop and terminate the program, no need of arrays and all…!!
Remember read the question carefully test cases are given just for better understanding of problem and actual cases may or may not include those mentioned test cases…
And Welcome to Codechef… Best of Luck and Enjoy Coding…
Take n numbers instead of 5…!
change the second for loop to a while loop as no. of iterations are unknown. use like while(1) & break it when u got 42 as input.