An easy level problem

rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.
Example

Input:
1
2
88
42
99

Output:
1
2
88

My code:

#include <stdio.h>
int main(void)
{
int x;
int a[100];
int i;
for (i=0; i<5; i++)
{
scanf("%d", &a[i]);

}


	printf("\n\n");
	for (i=0; i<x; i++)
	{
		if (a[i]!=42)
		{printf("%d", a[i]); printf("\n");}
		else goto hey;
	} hey:
	printf("\n");

return 0;

}

Please tell why this code is not getting accepted?

Why are you scanning only 5 digits? There is no such restriction. U have to take input until 42 comes. There can be more than 5 digits as well

1 2 3 4 5 6 7 …42 189 and so on.

1 Like

u can use jump statement ‘exit’ when a[i]=42.