C program to display a two digit number in reverse form

We can find the reverse of a two number using a simple formulae, first we will divide the two digit number into single digit numbers for example

23 will be divided into 2 and 3, but how we will divide it ? let’s see we are going to divide 23 by 10 and then the quotient obtained will be the first digit of the number and remainder obtained will be the last digit of the number for example

23 / 10 = 2

23 \% 10 = 3

Now we will use below formaulae to find the reverse of the number

rev = (last digit * 10) + first digit

eg : (3 * 10) + 2 = 32 (reverse of 23)

Now lets write the C program for it

#include<stdio.h>  int main(){  int last,first,n,rev; printf("Enter a number"); scanf("\%d",&n); last = n\%10; first = n/10; rev = (last * 10)+first; printf("Reverse of the number is: \%d",rev);  return 0; } 


C program to reverse a number

In the above code we store the first digit in the variable called first and last digit in the varaible called last and then we use the above formaulae to find the reverse.

Thank you for reading.

Tweet your queries and feedback to @PsychoCodes or leave a message on our Facebook page. You can also comment your questions below.

Also, don’t forget to subscribe to our Newsletter.

If you like this article, then please share it and help us grow.

Preorder and Postorder Traversal of binary tree in Python
02 September 2018

Binary Tree in Python
02 September 2018

Image Sharpening by High Pass Filter using Python and OpenCV
17 August 2018

Explaining Register variables in C with examples
17 August 2018

C program to generate all combinations of N-Bit Binary String
10 July 2018

Data Autosave System using PHP, MySQL and AJAX
06 July 2018

Понравилась статья? Поделиться с друзьями:
Добавить комментарий