Odd- why im getting runtime error for y code?

#include<stdio.h>
main()
{
int x,z,i,d[100];
printf(“enter the no. of persons vboarding”);
scanf("%d",&x);
label:
{
for(i=1; i<x && i%2==0; i++)
{
for(z=1; z<x/2; z++)
if(x/2<4)
{
d[z]=i;
for (z=1; z%2==0; z++)
printf("%d", z);
}
else
{
x=x/2;
goto label;
}
}
}
}

2 Likes

You have to read FAQ :wink: It’s written there :wink:

@shil::
The Run Time error that you are getting is NZEC.NZEC stands for Non Zero Exit Code. For C users, this will be generated if your main method does not have a return 0; statement. Other languages like Java/C++ could generate this error if they throw an exception.

Adding return 0 at the end of the code will fix runtime error.
But there are many errors apart from these.Even the logic is incorrect :(.
I had pointed and commented the errors in your code ,go through it once .

#include<stdio.h>
int main()
{
	int x,z,i,d[100];
	/*printf("enter the no. of persons vboarding");*/ /*There is No need for it,the input format in problem statements and and solution must be same*/
	scanf("%d",&x);
	label: 
	{
		for(i=1; i<x && i%2==0; i++)              /*Your program won't enter in this loop anytime
		{                                          As i=1 initially 1%2=1  so the condition 1%2==0 is false hence the loop termaintes always at i=1
												  */
				for(z=1; z<x/2; z++)
				if(x/2<4)
				{
					d[z]=i;
					for (z=1; z%2==0; z++)
						printf("%d\n",z);   /*New line character was missing.The output format in problem statements and
											and solution must be same*/

				}
				else
				{
					x=x/2;
					goto label;
				}
	}
	
	/*The Run time error that you are getting is NZEC(Non Zero Exit Code)
	That's because of missing of return 0 statement in C code.*/
	/*So add return 0*/

	return 0;
} 
4 Likes

If the outermost loop would have run,again @shil,you will get SIGSEGV Error due to out-of-bound index of array d.

1 Like

please use the code option from toolbar - http://i.imgur.com/ODZlB.png (you can edit your question)