0

Program to take input and gives output but stop processing input after reading in the number 42.check whether my pro is correct?

#include<iostream> using namespace std; int main() { int[10],i; cout<<"Enter any ten numbers"; for(i=1;i<=10;i++) { cin>>n[9]; } for(i=1;i<=10;i++) { cout<<"The output is"<<n[9]; if(n[10]=42) break; } return 0; }

13th Nov 2016, 2:27 PM
Rishabh rick
Rishabh rick - avatar
4 Answers
0
I don't understand. You want to read 10 numbers, but if a number is 42 it stops reading, then you print all the numbers readed?
13th Nov 2016, 5:01 PM
Lawrence Silva
Lawrence Silva - avatar
0
yes
13th Nov 2016, 5:02 PM
Rishabh rick
Rishabh rick - avatar
0
Here it is, any doubts, just ask. Remember to ident your code correctly. #include<iostream> using namespace std; int main() { int n[10], i; cout << "Enter any ten numbers:" << endl; for(i=1;i<=10;i++) { cin >> n[i]; if(n[i] == 42) { break; } } cout << "The output is: "; for(i=1;i<=10;i++) { cout << n[i] << " "; if(n[i] == 42) { break; } } cout << endl; return 0; }
13th Nov 2016, 5:26 PM
Lawrence Silva
Lawrence Silva - avatar
0
Thanks for the code bro I often get confused in nested loops
14th Nov 2016, 2:44 AM
Rishabh rick
Rishabh rick - avatar