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; }
4 ответов
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?
0
yes
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;
}
0
Thanks for the code bro I often get confused in nested loops