Sunday, 9 March 2014

Write a C program to reverse a number using function.

#include<stdio.h>
int reverse(int);
main()
{
    int n,b;
    printf("Enter a number=");
    scanf("%d",&n);
    b=reverse(n);
    printf("\nThe reverse number=%d",b);
}

int reverse(int a)
{
    int rev=0;
    while(a)
    {
        rev=rev*10+a%10;
        a=a/10;
    }   
    return rev;
}

No comments:

Post a Comment