1 / 3
Nov 2020

I,m trying to solve TEST - Life, the Universe, and Everything.
Make few codes.
Always “wrong answer”.
All works in my compiler.

#include
#include
#include
using namespace std;
int main()
{
int numb[1000], i, j;
cout << “Input:” << endl;
for (i=0;;++i)
{
cin >> numb[i];
if (numb[i]==42)
break;
j=i+1;
}
cout << endl;
cout << "Otput: " << endl ;
for (i=0;i!=j;++i)
cout << numb[i] << endl;
return(0);
}

what’s wrong with the code

  • created

    Nov '20
  • last reply

    Nov '20
  • 2

    replies

  • 554

    views

  • 3

    users

Your output must match the example output exactly. So you don’t want any of the lines highlighted above.

Also, what happens if there are more than 1000 numbers?

I guess you could use this code to avoid the problem of the number of inputs exceeding 1000.

#include<bits/stdc++.h>
int main()
{
        int x;
        while(cin >> x)
        {
        if(x == 42){break;}
        else{cout << x << endl;}
        }
}

Suggested Topics

Want to read more? Browse other topics in Online Judge System or view latest topics.