Programming Examples

Write a program entered number check the number is even or odd by using goto statement.


 Write a program to detect the entered number as to whether it is even or odd. Use the goto statement.

Solution

# include <stdio.h>
int main()
{
int x;
printf(" Enter a Number :");
scanf("%d",&x);
if(x%2==0)
goto even;
else
goto odd;
even :
printf("\n %d is Even Number.",x);
return;
odd:
printf("\n %d is Odd Number.",x);
return 0;
}
Output

OUTPUT:

Enter a Number : 5

5 is Odd Number.


Explanation:

 In the above program, a number is entered. The number is checked for even or odd with modules division operator. When the number is even, the goto statement transfers the control to the label even. Similarly, when the number is odd the goto statement transfers the control to the label odd and respective message will be displayed.

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz