Program to print the number in reverse order.

Here, we have a basic program example to print number in reverse order using different languages. This program is created in c language, c++, Java, and Python.

Code to reverse the number in C language

#include <stdio.h>
void main(){
    int num,r,sum=0,t;

    printf("Input a number: ");
    scanf("%d",&num);

    for(t=num;num!=0;num=num/10){
         r=num % 10;
         sum=sum*10+r;
    }
printf("The number in reverse order is : %d \n",sum);
}

Code to reverse the number in C++ language

#include <iostream>
using namespace std;
int main()
{
      int num,r,sum=0,t;
      cout<<"Input the number : ";
      cin>>num;
      for(t=num;num!=0;num=num/10){
         r=num % 10;
         sum=sum*10+r;
        }

      cout<<"The number in reverse order is :  \n"<<sum;
}

Code to reverse the number in Python language

reversed_num = 0
num = int(input("Input the number: "))
while num != 0:
    digit = num % 10
    reversed_num = reversed_num * 10 + digit
    num //= 10

print("Reversed Number: " + str(reversed_num))

Code to reverse the number in Java language

import java.util.*;
public class reverse {
    public static void main(String[] args) {     
         int num,r,sum=0,t;

	System.out.println("Enter the number of terms :  ");
        Scanner s=new Scanner(System.in);
        num = s.nextInt();

        for(t=num;num!=0;num=num/10){
         r=num % 10;
         sum=sum*10+r;
           }
        System.out.println("The number in reverse order is : "+sum);

      }
}