Reverse The Number Codechef Solution

Hello Programmers In this post, you will know how to solve the Reverse The Number CodeChef Solution.

Reverse The Number Codechef Solution
Reverse The Number Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

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 Solutions 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 Solutions 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 Solutions 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());
	}
}
Ezoicreport this ad

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

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Finding Square Roots Codechef Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad