Why is my code wrong?

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
scanf("%d",&n);
while(n!=42)
{printf("/n%d",n);
scanf("%d",&n);
}
getch();
}

Okay here you go.

  1. The print statement should be like printf("%d\n", n) since you need to leave a live AFTER every output and not before.

  2. You should remove the getch(); because the program won’t end unless it accepts another input after the specified inputs in the question.

  3. Also, I changed the void main() to int main() and added a return 0; at the end.

I got AC with the following changes.

1 Like

Hello aman_joshi668

although additya1998 has mentioned all the problem in your code here is the AC version of your code with minimal changes … :slight_smile:

#include 

int main() {
	int n ;
	while(1){
		
		scanf("%d",&n) ;
		if(n == 42)
			break ;
		printf("%d\n",n) ;
	}
	return 0;
}

1 Like

thanks
for helping me

you can also look for this discussion on the same problem

http://discuss.codechef.com/questions/7640/why-do-i-get-wrong-answer

@ma5termind linked question is not the correct one for discussing problems

do not use conio.h header on CodeChef :wink:

mention not bro :slight_smile:

@betlista
I have not used conio.h in my code … not in the mentioned link … :slight_smile: