+ ShareSpark.net » :::: Study / Technical / Programming Section » Programming Languages (Discussions & Helpdesk)
|- [c++]Reverse Number Problem


10% SBI and 10% Discount

[c++]Reverse Number Problem

0 Members and 1 Guest are viewing this topic.

August 18, 2014, 12:49:42 AM
  • Junior Mod (Inactive)
  • Elite Forces
  • ***
  • Topic Author
  • Thank You: 383
  • Reputation: 287
  • Activity:
    0%
  • Country: in
  • Posts: 1106
  • Topics: 575
  • Join Date: Feb 2013
  • Learner
here is code
Quote
#include<iostream>
#include<conio.h>

using namespace std;

main()
{
    int a , b=0;
   
    cout<<"enter any number you want to reversed :- \n";
    cin>>a;
   
    while(a!=0)
    {
        b=b*10;
        b=b+a%10;
       
        a=a/10;
       
    }
    cout<<b;
   
   
    getch();
}
it's working great but when i input any number which end with zero like 700 then it's reverse it to 7 not 007 how can i solve it..?

Share this topic on FacebookShare this topic on GoogleShare this topic on MySpaceShare this topic on TwitterShare this topic on Yahoo

« Last Edit: August 18, 2014, 12:51:01 AM by мαятιη199631 »



August 18, 2014, 01:13:36 AM
Reply #1
  • Premium Uploader
  • Conqueror (Inactive)
  • Special Member
  • *****
  • Thank You: 176
  • Reputation: 88
  • Activity:
    0%
  • Country: in
  • Posts: 655
  • Topics: 184
  • Join Date: Sep 2013
  • ShareSpark Member
You can use array for that. Store in array then read it in reverse >:D

August 18, 2014, 09:11:41 AM
Reply #2
  • Admin
  • Legend Member
  • ****
  • Thank You: 2343
  • Reputation: 624
  • Activity:
    23.6%
  • Country: in
  • Posts: 3658
  • Topics: 2237
  • Join Date: Dec 2013
  • ShareSpark Member


try this


#include<iostream>
using namespace std;

int main() {
int number, reverse = 0;
cout<<"Input a Number to Reverse and press Enter: ";
 cin>> number;     // Taking Input Number in variable number

   for( ; number!= 0 ; )
   {
      reverse = reverse * 10;
      reverse = reverse + number%10;
      number = number/10;
   }
   cout<<"New Reversed Number is:  "<<reverse;
   return 0;

}


August 18, 2014, 11:21:26 AM
Reply #3
  • Team SSX
  • Royal Member
  • ***
  • Thank You: 162
  • Reputation: 144
  • Activity:
    0.2%
  • Country: in
  • Posts: 925
  • Topics: 196
  • Join Date: Nov 2011
  • ShareSpark Member
Quote
int num;
cout<<"enter =>";
cin>>num;
cout<<"\nreverse is => ";
while(num!=0)
{
cout<<num%10;
num/=10;
}


Had the same problem once...long time back
This code should work.
:bounce:
  :bounce:

August 18, 2014, 12:41:30 PM
Reply #4
  • Hero Member
  • ***
  • Thank You: 4
  • Reputation: 83
  • Activity:
    1.2%
  • Country: in
  • Posts: 343
  • Topics: 5
  • Join Date: Sep 2013
  • ShareSpark Member
As mentioned above:-

         Write a program for reverse a word

August 18, 2014, 03:42:43 PM
Reply #5
  • Team SSX
  • Royal Member
  • ***
  • Thank You: 162
  • Reputation: 144
  • Activity:
    0.2%
  • Country: in
  • Posts: 925
  • Topics: 196
  • Join Date: Nov 2011
  • ShareSpark Member
Reversing a String.(include string.h)
Code: [Select]
main()
{
char str[50],rev [50],c;
int i=0,j;
cout<<"enter =>";
gets(str);
j=strlen(str)-1;
for(i=0;i<strlen(str);i++)
{rev[i]=str[j--];}
rev[i]='\0';
cout<<"reverse is ===>";
puts(rev);
}


:bounce:
  :bounce:

August 18, 2014, 10:32:20 PM
Reply #6
  • Junior Mod (Inactive)
  • Elite Forces
  • ***
  • Topic Author
  • Thank You: 383
  • Reputation: 287
  • Activity:
    0%
  • Country: in
  • Posts: 1106
  • Topics: 575
  • Join Date: Feb 2013
  • Learner
;D tushar thank man!!!..love you bhai O:-)

August 18, 2014, 11:15:23 PM
Reply #7
  • Team SSX
  • Royal Member
  • ***
  • Thank You: 162
  • Reputation: 144
  • Activity:
    0.2%
  • Country: in
  • Posts: 925
  • Topics: 196
  • Join Date: Nov 2011
  • ShareSpark Member

September 01, 2014, 12:02:12 AM
Reply #8
  • Semi Newbie
  • **
  • Thank You: 0
  • Reputation: 0
  • Activity:
    0%
  • Country: pk
  • Posts: 6
  • Topics: 0
  • Join Date: Dec 2013
  • ShareSpark Member
#include<sdtio.h>
#include<conio.h>
void main()
{
clrscr();
int b,a;
printf("Enter Number");
scanf("%d",&a);
while(a>0)
{
b=a%10;
printf("%d",b);
a=a/10;
}
getch();
}

i think this code work  :yahoo:
« Last Edit: September 01, 2014, 12:03:01 AM by Mughal125 »

Tags:
 

Related Topics

  Subject / Started by Replies Last post
0 Replies
1293 Views
Last post September 22, 2011, 03:33:53 AM
by Admin ♥♫
5 Replies
1961 Views
Last post February 23, 2013, 03:47:02 PM
by DΔи¡єL ΩCєαи
0 Replies
205 Views
Last post June 07, 2018, 05:30:50 AM
by kiteflyy
0 Replies
372 Views
Last post July 08, 2018, 02:23:40 PM
by shahzaibjaan
0 Replies
178 Views
Last post August 06, 2018, 03:33:04 PM
by shahzaibjaan




Back to top