Brijmohan lal Sahu - Facebook
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, November 30, 2014

Program to create an infinite loop using goto and find even or odd number in C.




Code Box
---------------------------------------------

/*Program to create a controlled loop Using goto */

/* goto is a jump statement in C  has the capacity to control the normal flow
of program */

#include<stdio.h>
#include<conio.h>
void main()
{
int num,ans;
clrscr();

up:

printf("\nEnter a Number:");
scanf("%d",&num);

if(num%2==0)
{ printf("\n %d is Even",num);
}
else
{ printf("\n %d is Odd",num);
}

printf("\nWant to Stop!! press 1");
scanf("%d",ans);

if(ans==1)
{
printf("\nOut");
exit(0);

/*You may be notice while executing this program that even exit() can not able to break the infinite loop */ 

}

goto up;

getch();
}

No comments: