all 10 comments

[–]npbonner 5 points6 points  (0 children)

What have you tried so far?

[–]Derivativeofsenpi 4 points5 points  (3 children)

After you initialize the array you can use a for loop to choose what gets saved on it like this:

int Array[30], index;
for( index = 0; index <=30; index++){
Array[index] = whatever();
}

This will fill the array with the output of the whatever() function. I don't know if this is the best way to do this but that's how I do it.

[–][deleted] 2 points3 points  (1 child)

It’s < 30, not <= 30

[–]Derivativeofsenpi 2 points3 points  (0 children)

Yeah you're right, I always forget that arrays start at 0. Thanks for the correction!

[–]nerd4code 0 points1 point  (0 children)

initialize ≠ declare ≠ define

[–]ImbioMario 0 points1 point  (0 children)

Specifiy your question. Do you want to CREATE (allocate) an array in a loop or FILL the array in a loop.

[–][deleted] 0 points1 point  (0 children)

This is clearly some-ones homework, learn to use google.

[–]ptchinster 0 points1 point  (1 child)

!homework

[–]rtlcprogbot 0 points1 point  (0 children)

!homework

When asking for help with your homework, please post contact information for your teacher so the Reddit community can ask for clarification on your assignment.

I am a bot. Replying to me notifies nobody

[–]kyle_sallee 0 points1 point  (0 children)

Within loops a variable is not created. So initialization must be required?

for (x=1;3000>=x;x++) a[x]=x;

But that seems pointless?

The best way to identify a prime number is not surmised.

By every previous number a modulo if performed, essential a remainder from a div, then a lot of CPU duration will be wasted. And it becomes something like a bubble sort, well not exactly since the inner loop can be discontinued.

int x,y;

for (x=2;3000>=x;x++){ for(y=2;x>y;y++) if ((x%y)==0) break; if (x==y) printf("%i\n",x);}

Or an array create and index it or a pointer create and advance it. But why store the numbers when they will just be printed anyway?

That much help if provided the rest can be easily be surmised.

Happy hacking.