Computer Science, asked by navnathdudhate4943, 10 months ago

Write a program to reverse a given number.

Answers

Answered by ankitgupta82
7

Explanation:

To understand this example, you should have the knowledge of the following C programming topics:

C Programming Operators

C while and do...while Loop

Reverse an Integer

#include <stdio.h>

int main() {

int n, rev = 0, remainder;

printf("Enter an integer: ");

scanf("%d", &n);

while (n != 0) {

remainder = n % 10;

rev = rev * 10 + remainder;

n /= 10;

}

printf("Reversed number = %d", rev);

return 0;

Mark as Brainlist

Answered by stylishtamilachee
1

Answer:

public class Test

{

static int RevNum( int num )

{

int num2 = num ;

int dig, q, rnum = 0 ;

while (num2 > 0)

{

q = num2/10 ;

dig = num2%10;

rnum = rnum*10 + dig ;

num2 = q ;

}

return rnum ;

}

public static void main ( String args[ ] )

{

int n1 = 345, n2 = 672, n3 = 13602 ;

int s = 0 ;

s = RevNum(n1) ;

System.out.println("Reverse of" + n1 + "is :" + s) ;

s = RevNum(n2) ;

System.out.println("Reverse of" + n2 + "is :" + s) ;

s = RevNum(n3) ;

System.out.println("Reverse of" + n3 + "is :" + s) ;

}

}

Output produced is:

Reverse of 345 is : 543

Reverse of 672 is : 276

Reverse of 13602 is : 20631

Similar questions