Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I need help about array.

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to make program that asks user to enter n, the number of elements of the string (not more than 50). If n is out of range print the message and request re-entry. Then enter n numbers that will print in the reverse order of the entry order.

What can I change in my code so I can get correct results like in this example:
(input) 55 0 5 1 2 3 4 5

(output)
Enter number of strings: Wrong input!!
Enter number of strings: Wrong input!!
Enter number of strings: Enter 5 numbers:
5, 4, 3, 2, 1,

This is code I wrote by now:
 
Rancher
Posts: 508
15
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Alenko - you use a loop to read in the numbers. Don't you just need another loop to output them, but in reverse order?
John
 
John Matthews
Rancher
Posts: 508
15
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, I can see you do a printf() after your loop where you read in the numbers. If the number of numbers is 5, then they will be stored in a[0..4]. But then that printf() after the loop will output a[i=n=5], which hasn't been set.

That printf() needs to be in a loop where you make i go from 4..0 (if n is 5) and output a[i] each time.
reply
    Bookmark Topic Watch Topic
  • New Topic