I am supposed to write a program that prints out the first n primes, where n is input by the user. I am supposed to write my program in its own directory in three files: primes.h, main.c, and is_prime.c
This is what the output is supposed to look like:
PRIMES WILL BE PRINTED.
How many do you want to see? 3000
Code:
1: 2
2: 3
3: 5
4: 7
5: 11
.....
25: 97
26: 101
.......
2998: 27431
2999: 27437
3000: 27449
........
10000:
is_primes.h:
Code:
#include <stdio.h> #include <stdlib.h> int is_prime(int n);
Code:
#include "primes.h"
int is_prime(int n)
{
int k, limit;
if (n == 2)
return 1;
if (n % 2 == 0)
return 0;
limit = n / 2;
for (k = 3; k <= limit; k += 2)
if (n % k == 0)
return 0;
return 1;
}
Code:
#include "primes.h"
int main(void)
{
printf("PRIMES WILL BE PRINTED\n\n");
printf("How many do you want to see? \n");
scanf("%5d",
return 0;
}


