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:
Post a Comment