3 / 5
Mar 2017

include

using namespace std;

int main()
{
int n,i;
cin>>n;
int a[n];
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
{
if(a[i]==42)
break ;
else
cout<<a[i];
}

}// problem link (http://www.spoj.com/problems/TEST/)

  • created

    Mar '17
  • last reply

    Mar '17
  • 4

    replies

  • 1.3k

    views

  • 3

    users

  • 1

    like

The output format is not correct
In SPOJ the output format should match with the required format.
It should be

cout<<a[i]<<endl;

as required, that is every output should be in new line.

and also

basic header file is also not included for the functionality of cin and cout i.e

include

I think that's the only corrections you need in this code.

include

using namespace std;

int main()
{
int n,i;
cin>>n;
int a[n];
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
{
if(a[i]==42)
break ;
else
cout<<a[i]<<"endl";
}

}
// sir, i corrected out all the mistakes but compiler shows wrong answer..

Your code is wrong. There is no n in the input.
And the way you wrote endl was wrong.

using namespace std;

int main()
{
int a;

while(1)
{
    cin>>a;

    if(a==42)
    break;

    else
    cout<<a<<endl;
}

}

Yes,it worked i got it.Thanku@shraeyas..and please help me if i stuck in any problem..And once again thanku for ur vulnerable suggestion...:slight_smile: