SSL Certificate
  • write a program that prints out the first n primes, where n is input by the user
2. Exercise 192 after chapter 4 (40 pts)
Please name your submission of this problem as: primes.h, is_primes.c, main_1.c, main_2.c, main_3.c and main_4.c
main_1.c corresponds to the main.c in your textbook.
The problem in textbook is: write a program that prints out the first n primes, where n is input by the user. This is example 1. After the example in the book it says to write your program in its own directory in three files: primes.h, main.c, and is_prime.cHere is some of the program:
In file primes.h:
#include <stdio.h>
#include <stdlib.h>

intis_prime(int n);

in file is_prime.c

#include “primes.h”

intis_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;
}



After you finish requirements in the textbook, rename your main.c file as main_1.c and then modify it to make files main_2.c, main_3.c and main_4.c, each of which implements a different functionality (see examples).
Given an integer N, main_1.c outputs the first N primes starting from 2.
Given an integer N, main_2.c outputs the all primes numbers less than N.
Given an integer N and an integer X, main_3.c outputs primes with index X+1, X+2, …, X+N in prime number sequence starting from 2.
Given an integer N and an integer Y, main_4.c outputs N primes starting from integer Y.
While testing main_1.c, compile using the following command (replacing main_1.c with main_2.c when testing main_2.c. same for other main files):
::gccis_primes.c main_1.c primes.h
Example 1(output of program compiled from main_1.c, is_primes.c and primes.h):
PRIMES WILL BE PRINTED
How many do you want to see? 3000
1: 2
2: 3
3: 5
4: 7
5: 11
6: 13
7: 17
……
2995: 27407
2996: 27409
2997: 27427
2998: 27431
2999: 27437
3000: 27449

Example 2(output of program compiled from main_2.c, is_primes.c and primes.h):

Primes between 1 and N will be printed
Please input the value of N: 27450
1: 2
2: 3
3: 5
4: 7
5: 11
6: 13
7: 17
8: 19
……
2994: 27397
2995: 27407
2996: 27409
2997: 27427
2998: 27431
2999: 27437
3000: 27449
Example 3(output of program compiled from main_3.c, is_primes.c and primes.h):

PRIMES WILL BE PRINTED
How many do you want to see? 33
Beginning at what index? 700
700: 5279
701: 5281
702: 5297
703: 5303
704: 5309
705: 5323
706: 5333
707: 5347
……
723: 5477
724: 5479
725: 5483
726: 5501
727: 5503
728: 5507
729: 5519
730: 5521
731: 5527
732: 5531

Example 4(output of program compiled from main_4.c, is_primes.c and primes.h):

PRIMES WILL BE PRINTED
How many do you want to see? 33
Beginning at what number? 5278
700: 5279
701: 5281
702: 5297
703: 5303
704: 5309
705: 5323
706: 5333
707: 5347
708: 5351
……
722: 5471
723: 5477
724: 5479
725: 5483
726: 5501
727: 5503
728: 5507
729: 5519
730: 5521
731: 5527
732: 5531
- Doesn’t implement primes.h or is_primes.c: -5 pts/each

Excellent Answer
=================
*Instant Download

Write a review

Please login or register to review

write a program that prints out the first n primes, where n is input by the user

  • $9.99


*All your data are SECURED & ENCRYPTED using a valid, trusted server certificate (Comodo SSL) and we don't store credit card information on our servers and all Payments are SECURED & handled by Paypal.
SSL CertificatePaypal

Tags: c, programming, primes.h, is_primes.c, main_1.c, main_2.c, main_3.c, main_4.c, main_1.c, primes