C Programming

C Program to read the four-digit number and display them 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

When a 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 remainders is 4.
after that number = number / 10 display value 4…
the value of the number becomes 123 this process is repeated 3 times and the final output will be 4321

Write a C program to read a 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();
}

Related Articles

Back to top button

Adblock Detected

Please turn off your Adblocker to view your content.