# Thread: Having the output of a While loop feed directly into an array

1. ## Having the output of a While loop feed directly into an array

The below program (that I didn't write) prints to the screen the first 100 prime numbers. I am tiring to get it to put the 100 prime numbers into an array.

Code:
```
#include <stdio.h>

int main(int argc, char *argv[]) {
int p, number;
int count=0;

p=2;

while (count < 100) {

number=2;
while (number < p) {
if (p % number == 0) {

number = p;
}
number=number+1;
}

if (number == p) {
printf("%03d. prime number is %4d\n", count+1, p);
count=count+1;
}
p=p+1;
}

return 0;
}```
I started by defining an array "int prime [100];" and the printf function above and replaced it with "p=prime[]" then "p=prime[100]" , then "p=prime" and finally "prime=p", but it wouldn't work

2. I think you are going to want to read up on arrays a little more. What you want to do is very simple, and very achievable with some knowledge on arrays. If you have read a tutorial or something and you aren't sure about them, then ask what you aren't sure about instead.

It's better to get a general understanding of the way something works than to just try to apply it in an example.

There are plenty of guides on arrays, just google "C Arrays".

3. Hey Kevin, welcome to the forum.

You're like me - basically backwards, sometimes. Not:
p=prime[100]

but

prime[count] = p;, right inside your if statement near the bottom of the program.

And since this IS C:

prime[count++] = p; //and you can delete the count = count + 1

Make sure you have:
int prime[100] = 0;

in the code, right at the top of main();