i tried to write a prrogram using array which take 5 digits as in put and reverse that digits,but that program doesn't work.below u can see my program

{
    int no[5];
    cin>>no[5];
    for(int i=5;i<=0;i--){
    cout<<no[i];
    }
}

try 2 correct the errors.

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks)

Well, first off you are not asking the user for one of the designated arrays. you would need something like this:

for(int x=0;x<5;x++)
   cin >> no[x];

Next: Your loop is not going to work. It should be:

for(int i=4;i>=0;i--)
   cout<<no[i];

On another Note: Be sure to use 'code' tags when posting your code. As well, using header files might help too. Thanks!
aannd, just to be user friendly you may want to tell the user what to do, instead of just leaving them with a blank screen and expecting them to type in numbers.

Edited 6 Years Ago by restrictment: n/a

how i can use arrays convert 1234 which is given as input and display it like 4321.

Just put the two pieces of code I gave to you together...

ya i know it reverses the number but i want to give input like this 1234 not like as below

1
2
3
4

ya i know it reverses the number but i want to give input like this 1234 not like as below

1
2
3
4

It does print them horizontally..if you would like them to print out vertically, just add an endl statement to the end of the second loop.

This article has been dead for over six months. Start a new discussion instead.