Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

C Program – Goto Statement to find Even Or Odd & Positive or Negative Number

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.

#include 

int 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.



This post first appeared on TutorialsMade - Ultimate Tutorial, please read the originial post: here

Share the post

C Program – Goto Statement to find Even Or Odd & Positive or Negative Number

×

Subscribe to Tutorialsmade - Ultimate Tutorial

Get updates delivered right to your inbox!

Thank you for your subscription

×