Program runs perfectly in my compiler but gives error on codechef

The following program is giving a wrong solution result on codechef but is running perfectly in my compiler, Please help

#include<iostream>

#include<stdio.h>

using namespace std;

int main()

{

	int a[100],n,i;
	cout<<"\nEnter the no of numbers\t";
	cin>>n;
	if(n>100)
		return 0;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	cout<<"\nThe numbers are\n";
	for(i=0;i<n;i++)
	{
		if(a[i]==42)
    
			break;
		cout<<a[i]<<"\t";
	}
	return 0;
}

This part from FAQ should be interesting for you:

If your program starts by printing ‘Enter the number’ and the problem does not tell you to do so, then since this is not part of the correct output, you will be never be judged correct regardless of what the rest of your program does.

You are not first who is asking, where is such example from?

Mine is the same, here it is:

#include <iostream>
using namespace std;
int main()
{
    int in;
    int loop = 1;
    while (loop == 1)
    {
        cin >> in;
        if (in != 41)
        {
            cout << in << endl;
        }
        if (in == 42) return 0;
    }
    return 0;
}

try what your program prints for 1 41 42 :wink: It’s not working for example input too…

//