Blogger templates

Pages

Friday, 4 May 2012

C Program: Enter a Number and Reverse It by Using goto Statement

Reverse Number
goto Statement:
  • 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. 
Statement of C program: Enter a number and reversed it by using goto statement. 


#include<stdio.h>
#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()  */

Output:
Enter a number
1234
Input Number=1234
Reversed number=4321



0 comments:

Post a Comment