Sunday, 15 December 2013

C Program to Reverse a Given Number

#include < stdio.h>
 
void main()
{
    long  num, reverse = 0, temp, remainder;
 
    printf("Enter the number\n");
    scanf("%ld", &num);
    temp = num;
    while (num > 0)
    {
        remainder = num % 10;
        reverse = reverse * 10 + remainder;
        num /= 10;
    }
    printf("Given number = %ld\n", temp);
    printf("Its reverse is = %ld\n", reverse);
}

Output

 Enter the number
 567865 
Given number   =  567865 
Its reverse is =  568765 

For More Details Please Visit Ictjobs.info

No comments: