Reverse the digits of a number for both positive and negative numbers. - C Statement

C examples for Statement:do while

Description

Reverse the digits of a number for both positive and negative numbers.

Demo Code

#include <stdio.h>

int main (void){
    int number, right_digit;

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

    if (number < 0)
    {// w w w.j ava2 s .  co m
        number *= -1;
        printf("-");
    }

    do
    {
        right_digit = number % 10;
        printf ("%i", right_digit);
        number = number / 10;
    }
    while (number != 0);

    printf ("\n");
    return 0;
}

Result


Related Tutorials