Computer Science, asked by pratiksharelekar, 11 months ago

write a program to display given Enter five digit number and reverse are same?? please give me answer in turboo c++​

Answers

Answered by Tejas1582
0

Explanation:

this is the simplest way to do

Attachments:
Answered by varadhabala29
0

Answer:

cin>>a;

int temp=a,r=0,rev=0;

while(a!=0)

{

r=a%10;

rev=rev*10+r;

a=a/10;

}

cout<<"The reverse of the inputted number is"<<rev;

Explanation:

I hve used ++. I have excluded the main() and the header files. you can add the corresponding header files here. The program logic is a bit dificult. I will try my best in explaining correctly. Firstly, input a number as a. Now, we need a temporary variable say temp and two other variables, r and rev. Here, r is used to store the remainder and rev is used to store the reversed number. Coming to the looping section, we use a while loop and will iterate until the value of a becomes 0. The first step is that we take the remainder of the number by using the modulus operator. Ie., a%10 returns the last digit of the number. We store this remainder, r into rev. Rev=rev*10+r is used for the reversing purpose. Rev*10 is used to change the position of the number from ones place to tens place and then to the hundredth place as we have studied in lower classes. Now, along with a change in the position, we add the remainder(the last digit). Now, we divide the original number by 10. This will remove the last digit from the original number. This process continues till a becomes 0. Last, the reversed number will be printed.

Similar questions