Reverse The Number Codechef Solution

Hello coders, today we are going to solve Reverse The Number CodeChef Solution.

Reverse The Number Codechef Solution
Reverse The Number Codechef Solution

Problem

Given an Integer N, write a program to reverse it.

Input

The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N.

Output

For each test case, display the reverse of the given number N, in a new line.

Constraints

  • 1 <= T <= 1000
  • 1 <= N <= 1000000

Example

Input:

4
12345
31203
2123
2300

Output:

54321
30213
3212
32

Reverse The Number CodeChef Solution in Python

for _ in range(int(input())):
    N = int(input())
    Rev = 0
    while N > 0:
        Rev = Rev * 10 + N % 10
        N = N // 10
    print(Rev) 

Reverse The Number CodeChef Solution in CPP

#include<bits/stdc++.h>
using namespace std;
int main(){
   int a,c,ck=0,n,i,cc,dd,rem=0,rev=0,j=1;
   cin>>n;
   for(i=0; i<n; i++){
    cin>>a;
    while(a!=0){
        rem = a%10;
        rev = rev*10 + rem;
        a/=10;
    }
    cout<<rev<<endl;
    rev=0;
   }
}

Reverse The Number CodeChef Solution in JAVA

import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int tc = 0; tc < T; tc++) {
			int N = sc.nextInt();
			System.out.println(solve(N));
		}
		sc.close();
	}
	static int solve(int N) {
		return Integer.parseInt(new StringBuilder(String.valueOf(N)).reverse().toString());
	}
}

Disclaimer: The above Problem (Reverse The Number) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.

Sharing Is Caring

Leave a Comment