C Codes · General Discussions

Reverse an Integer – C Code

Github Link. 

#include 
int main()
{
    int n, revnum = 0, rem = 0;

    printf("Enter an integer: ");
    scanf("%d", &n);

    while(n != 0)
    {
        rem = n % 10;
        revnum = revnum *10 + rem;
        n = n / 10;
    }

    printf("Reversed Number = %d", revnum);
    return 0;
}

Let me Know What you Think!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s