When you gave 3
as input, the if
condition is true and main()
will be called a 2nd time.
Then you gave an even number as input in which case, the flow of control won't enter the body of if
and just print the "EVEN NUMBER ENTERED" message and the program control exits the 2nd main()
.
Now the control goes back to the place where the main()
was recursively called and executes what is left of the first main()
call which happens to be the same "EVEN NUMBER ENTERED" message.
See this about making main()
recursive. A recursive main()
is not considered good.
Consider making another function and then calling it from main()
like
int fn()
{
int num;
printf("Enter an EVEN Number: ");
scanf("%d",&num);
if (num%2!=0)
{
printf("WRONG INPUT\n\n");
return fn();
}
printf("EVEN NUMBER ENTERED\n");
}
Or use else
as you did first.