Question about arrays?? PLease read..

This is a discussion on Question about arrays?? PLease read.. within the C Programming forums, part of the General Programming Boards category; Ok, I'm not an expert here of course but I'm having a difficult time with array's. Here's the question... User ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    3

    Question about arrays?? PLease read..

    Ok, I'm not an expert here of course but I'm having a difficult time with array's. Here's the question...

    User enters in a number regarding how many inputs to be entered (ie. 2.3, 4.5, 2.0). Then the user is asked to enter a number 1-10. Now what this number does is starts at the predetermined array and goes back wards to the beginning.

    EX:
    Enter X: (user puts 4)
    Enter Y: (user puts 3)

    output:
    Enter number 1: (user input 2.0)
    Enter number 2: (user input 3.4)
    Enter number 3: (user input 1.1)
    Enter number 4: (user input 2.9)

    break

    The last three numbers you have entered are: 2.9, 1.1, 3.4

    How in the world can I start at a specific array and go backwards? Hope you can help.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Code:
    for (i = 10; i >= 0; i--)
    {
    	printf ("Array element %d is %d\n", i, myarray[i]);
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Hammer
    Code:
    for (i = 10; i >= 0; i--)
    {
    	printf ("Array element %d is %d\n", i, myarray[i]);
    }
    Keep in mind that arrays go from: 0 to Size-1.

    Thus, if you do:

    int array[10];

    You access the elements as:

    array[0] = 1;
    ...
    array[9] =10;

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    err... yeah.. 'spose I should have included the array declaration too

    >myarray[11];
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 07:59 AM
  2. Just a quick question about character arrays
    By Welshy in forum C Programming
    Replies: 3
    Last Post: 04-03-2006, 08:20 AM
  3. How should I read this file (i/o question)
    By mmattax in forum C Programming
    Replies: 13
    Last Post: 01-17-2006, 11:16 AM
  4. basic question to Arrays
    By doneirik in forum C++ Programming
    Replies: 1
    Last Post: 01-25-2005, 02:57 AM
  5. Yet another read file question ...
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 02-28-2002, 11:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21