C Program to read four digit number and display it in reverse order

C Program to read four digit number and display it in reverse order, program to reverse numbers, C program to read three digit number and display it in reverse order.

Write a c program where program should read four digit number and display those entered number into reverse order.

C Code


#include<stdio.h>
#include<conio.h>
int main(void){

        int number;

        printf("Enter a four digit number:");
        fflush( stdout );
        scanf("%d", &number);

        printf("the number in reversed order:");

        printf("%d", number%10);
        number = number/10;

        printf("%d", number%10);
        number = number/10;

        printf("%d", number%10);
        number = number/10;

        printf("%d", number%10);

        return 0;
}

Output

C Program to read four digit number and display it in reverse order

When user enters the value 1234

there is printf("%d",number%10); statement is used. It shows the value 4 because when 1234 is divided by 10 remainder is 4.

after that number = number / 10 display value 4...

the value of number becomes 123 this process is repeated 3 times and the final output will be 4321


Write a C program to read three digit number and display it in reverse order.

C Code


#include<stdio.h>
#include<conio.h>
void main(){

        int number;

        printf("Enter a three digit number:");
        fflush( stdout );
        scanf("%d", &number);

        printf("the number in reversed order:");

        printf("%d", number%10);
        number = number/10;

        printf("%d", number%10);
        number = number/10;

        printf("%d", number%10);

        getch();
}

Output

Write a C program to read three digit number and display it in reverse order.

You May Also Like...