goto Statement:
void main()
- goto statement is used to transfer control from one location to another location.
- goto is a Keyword.
- Keywords are the reserved words.
- There are 32 keywords in C.
#include<conio.h>
void main()
{ /* Start of main() */
int a,c,d;
b=0; // Assign value zero to 'b'
clrscr();
printf("Enter the value of a/n ");
scanf(" %d , &a");
d=a ; // Assign value of 'a' to 'd'
BEGIN: c=a%10 // where BEGIN is a Lable
// % is a modulus operator. It is used for finding remainder value.
b=(b*10)+c;
a=a/10; // It is also written as a/=10
if(a>0)
goto BEGIN; // goto is a Keyword
printf(" Input Number=%d/n" , d);
printf(" Reversed Number=%d/n" , b)
} /* End of main() */
} /* End of main() */
Output:
Enter a number
1234
Input Number=1234
Reversed number=4321
0 comments:
Post a Comment