In this article, we will discuss the concept of the C program to reverse a number using loops
In this post, we are going to learn how to find reverse number of the given number in C programming language
Program 1
The program allows the user to enter a number and it displays the reverse pattern of the given number using for loop in C language
when you are entered 45678,
The output will be displayed as 87654
#include <stdio.h> #include <stdlib.h> int main() { int num,rem,reverse=0; printf("Enter a number for find reverse\n"); scanf("%d",&num); printf("You entered %d\n",num); for(;num!=0; num=num/10){ rem=num%10; reverse=reverse*10+rem; } printf("Reverse of the given number %d",reverse); getch(); return 0; }
When the above code is executed, it produces the following result
Explanation
Program 2
The program allows the user to enter a number and it displays the reverse pattern of the given number using while loop in C language
when you are entered 13579,
The output will be displayed as 97531
#include <stdio.h> #include <stdlib.h> int main() { int num,reverse=0,rem; printf("Enter a number for find reverse\n"); scanf("%d",&num); printf("You entered %d\n",num); while(num!=0){ rem=num%10; reverse=reverse*10+rem; num/=10; } printf("Reverse number %d\n",reverse); getch(); return 0; }
When the above code is executed, it produces the following result
Explanation
Program 3
The program allows the user to enter a number and it displays the reverse pattern of the given number using do-while loop in C language
when you are entered 54321
The output will be displayed as 12345
#include <stdio.h> #include <stdlib.h> int main() { int num,reverse=0,rem; printf("Enter a number for find reverse\n"); scanf("%d",&num); printf("You entered %d\n",num); do{ rem=num%10; reverse=reverse*10+rem; num/=10; }while(num!=0); printf("Reverse number %d\n",reverse); getch(); return 0; }
When the above code is executed, it produces the following result
Explanation
Suggested for you
Similar post
Reversed string in Java language
Reversed string in C++ language
C++ program to reverse a number using loops
Java program to reverse a number using loops
10 simple ways to add two numbers in Java In this article, we will discuss…
Write a Python program to find the first n prime numbers In this article we…
Python: Calculate Average of odd and even in a list using loops In this post,…
Python: Average of Odd & Even Numbers from User Input In this post, we will…
Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…
Python program to calculate the sum of odd and even numbers in a list In…
View Comments
Nice program . visit more good coding program collection Click Here