In this post, I am writing a straightforward C program to find whether the entered Number is Even or Odd as well as Positive or Negative.
Here is the entire program, copy-paste the code and run it.
#includeint main() { int n; //get the value from user printf("Enter a number:"); scanf("%d", &n); // using goto statements if (n % 2 == 0 && n > 0) goto a; else if (n % 2 != 0 && n 0) goto d; else goto e; a: printf("Number is Even and Positive"); goto stop; b: printf("Number is Odd and Negative"); goto stop; c: printf("Number is Even and Negative"); goto stop; d: printf("Number is Odd and Positive"); goto stop; e: printf("It's a zero"); goto stop; stop: return 0; }
Sample Outputs:
Enter a number:50 Number is Even and Positive -------------------------------- Process exited after 2.284 seconds with return value 0 Press any key to continue . . .
Enter a number:-2 Number is Even and Negative -------------------------------- Process exited after 3.433 seconds with return value 0 Press any key to continue . . .
I believe this post would have helped you to understand how to use the Goto statement.