Thread: fill an array with numbers from 1 to 10

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    144

    fill an array with numbers from 1 to 10

    I'm trying to do this question
    Code:
    If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
    This is the approach I'm trying to take.

    1. create an array from 1 to 10 and display
    2. divide each number in the array by 3 and 5
    3. sum up all the numbers which when divided by 3 and 5 gives a remainder of 0

    I'm having difficulty with step 1. I would like to automatically populate the array from numbers 1 to 10 instead of saying
    Code:
    int numbers[]={1,2,3,..}.
    Is this possible?

  2. #2
    Bit Fiddler
    Join Date
    Sep 2009
    Posts
    79
    Code:
        int numbers[arrayLen];
    
        for (count = 0; count < arrayLen; count ++)
            numbers[count] = count + 1;

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    "Question"? There's no question there.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing unique numbers to an array
    By yardy in forum C Programming
    Replies: 6
    Last Post: 12-27-2006, 09:15 PM
  2. question: reading numbers into an array
    By Lince in forum C Programming
    Replies: 15
    Last Post: 11-15-2006, 03:41 AM
  3. HELP:::MIX numbers in array
    By ypramesh in forum C Programming
    Replies: 9
    Last Post: 03-30-2006, 07:47 PM
  4. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM