Powered By Blogger

Saturday, December 25, 2010

C Program to find the reverse of a number

/* C Program to print the reverse of a number */

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main()
{
    int num;
    int count=0;
    int ctr;
    int mult=1;
    int result=0;

    printf("Enter the number\n");
    scanf("%d",&num);

    while(num>0)
    {
        mult=1;
        for(ctr=0;ctr<count;ctr++)
        {
            mult=mult*10;
        }
        result=result*mult;
        result=result+(num%10);
        num=num/10;
        count++;
    }

    printf("The Reverse of the given number is %d",result);
    return 0;
}

No comments:

Post a Comment