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.

Recommended Answers

All 5 Replies

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.