• Language

    C

  • Description

    Write a program that prompts the user to enter a four-digit integer and displays the number in reverse order.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    int four_digit_number, reverse;
    printf ("Enter the value of four digit number: ");
    scanf ("%d", &four_digit_number);
    (void) getchar ();
    reverse=(four_digit_number%10000-four_digit_number%1000)/1000+(four_digit_number%1000-four_digit_number%100)/10+(four_digit_number%100-four_digit_number%10)*10+(four_digit_number%10)*1000;
    printf ("Value of reverse: %d\n", reverse);
    putchar ('\n');
    system ("pause");
    return EXIT_SUCCESS;
}