Reversing the Digits of a Number - C Statement

C examples for Statement:while

Description

Reversing the Digits of a Number

Demo Code

#include <stdio.h>

int main (void)
{
    int number, right_digit;

    printf("Enter your number.\n");
    scanf ("%i", &number);

    while (number != 0)
    {//from w ww.ja  va 2 s .  co m
        right_digit = number % 10;
        printf ("%i", right_digit);
        number = number / 10;
    }

    printf("\n");

    return 0;
}

Result


Related Tutorials