Part 3: Call your program by the name: "program_003_store_first_1000_primes_in_an_ARRAY".
This program must create an array of integers, of size 1000. Then, it must store the first 1000 prime numbers in the array. Then, it must print out the contents of the array.
C Programming Language
Below is the c program to get first 1000 prime numbers abd those prime numbers to array and print out the umbers from array.
#include <stdio.h>
int main()
{
int n = 1000, i = 2, count, c, j=0;
int primeArray[1000];
for(count = 1; count <= n; i++)
{
// check c is prime or not
for(c = 2; c < i; c++)
{
if(i%c == 0)
break;
}
if(c == i) // c is prime
{
//add prime number to array
primeArray[j]=i;
count++; // increment the count of prime numbers
j++;
}
}
for(int k=0; k<1000; k++)
{
//Print the array element
printf(" %d ", primeArray[k]);
}
return 0;
}
Below is the output screenshot
Get Answers For Free
Most questions answered within 1 hours.