# Fill array allocated by user with logical order prime numbers

60 views

208/5000
Write a program that will fill prime numbers starting with the first prime number within a given range in an array?
* Number is a prime if it is is divisible only by 1 and itself.
* Size of array is user-defined.
* User defines number of elemenets in array.(needs to be dinamicly allocated)
* Print created array necessary at the end.

posted Apr 18, 2017

+1 vote

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

int main(void)
{
int *myarray;
int sizeofarray;
int count=0;

printf("Enter the size of array(example: 5000)\n");
scanf("%d", &sizeofarray);

myarray=calloc(sizeofarray, sizeof(int));

for (int i=208; i<=5000; i++)
{
for (int j=2; j<=i; j++)
{
if (i == j)
{
myarray[count++] = i;
printf("%d\n",i);
}
else if (i%j == 0)
break;
}
}
}
``````
Similar Questions
+1 vote

For Example:
the prime divisors of 450 are 4,5,3,3,2.

it is illegal to share some certain prime numbers in US and if you do so,you will get arrested.Follow this link to get more details :