Write a function intreverse(n) that takes as input a positive integer n and returns the integer obtained by reversing the digits in n. here are some examples of how your function should work. >>> in reverse(783) 387 >>> intreverse(242789) 987242 >>> intreverse(3)
Answers
Answered by
0
import java.util.Scanner;
public class Program
{
public static int intreverse(int n){
int reverse_num=0;
do{
int x=n%10;
reverse_num=(reverse_num*10)+x;
n/=10;
}while(n>0);
return reverse_num;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int number=sc.nextInt();
System.out.println("entered number:"+number+"\n"+"reverse number:"+Program.intreverse(number));
}
}
public class Program
{
public static int intreverse(int n){
int reverse_num=0;
do{
int x=n%10;
reverse_num=(reverse_num*10)+x;
n/=10;
}while(n>0);
return reverse_num;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int number=sc.nextInt();
System.out.println("entered number:"+number+"\n"+"reverse number:"+Program.intreverse(number));
}
}
Answered by
0
In python 3,
//function definition
def intreverse(n):
rev=0
while ( n > 0 ):
last = n % 10
rev = rev * 10 + last
n = n / 10
return rev
Sample I/O:
intreverse(369)
963
Read more on Brainly.in - https://brainly.in/question/5520215
Similar questions