Purchase Solution

C program to print first n prime numbers

Not what you're looking for?

Ask Custom Question

Write a program that prints out the first n primes, and n is input by the user. Example as follows:

How many do you want to see? 3000

1: 2
2: 3
....

25: 97
26: 101
....

2999: 27437
3000: 27449

Program should be written in three files:

primes.h
main.c
is_primes.c

Attached are parts of two files (primes.h, is_primes.c)

Explain how is_prime() works. Complete the program by writting main() in main.c. There are 168 primes that are less than 1000. Does the program confirm this? How many primes are there that are less than 10,000?

Purchase this Solution

Solution Summary

C code in solution assumes fair input to the program and has been tested for compilation with "gcc -Wall -ansi main.c is-prime.c", and for execution with inputs in the set (0-5, 168-170, 1230, 10000).

Solution Preview

Functionality of is_prime function is expressed in following steps.

1. Check whether the argument number (n) is 2. If it is 2 (first prime number) then return 1.

2. Check if n is a multiple of 2. If "n modulus 2" is 0, then n is a multiple of 2 and so it can not be a prime number. Function returns 0 in this ...

Purchase this Solution


Free BrainMass Quizzes
Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Javscript Basics

Quiz on basics of javascript programming language.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.