ECE 190 Midterm Exam 1 - Counting Primes, Exams of Introduction to Aerospace Engineering

Instructions for a programming assignment in which students are required to write a program to count the number of prime numbers less than a given positive integer n. The definition of a prime number and provides a sample run for the program. It also includes a list of the first 25 prime numbers between 1 and 100 and instructions for compiling and submitting the program.

Typology: Exams

2012/2013

Uploaded on 04/01/2013

ekan
ekan 🇮🇳

5

(1)

72 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ECE#190!Midterm(Exam(1!
Spring!2011!
Tuesday, February 15, 2011
In this assignment, you will need to write a program to count the number of primes less than n. A prime is a
number that is not a multiple of any positive number other than 1 and itself. 1 is not a prime by definition. 2 is a
prime because it is not divisible by any numbers other than 1 and itself; 4 is not a prime because it is divisible
by 2, and so on.
First, your program should ask the user "What is n? ". The user will reply with a positive integer n. You
will compute the number of primes less than n and will provide the answer in the format "There are m
primes less than n." followed by a newline where m is the actual number of primes found and n is the
number entered by the user. Sample run for your program when n is 191 should look like this:
What is n? 191
There are 42 primes less than 191
You may NOT use any functions from math.h. To aid you in debugging or testing, here is a complete list of
all 25 prime numbers between 1 and 100:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
71, 73, 79, 83, 89, 97
When you open a terminal do NOT type ece190. If you type ls in the terminal the output should include a
skeleton file as well as a Makefile. If you do not see this, please contact a TA.
The command make will compile your code, and the command make test will provide a basic functionality
check. You are responsible for developing your own test cases, if need be.
Name your program file exam1.c. You should compile your code either using make or as follows:
gcc -g -Wall -Werror -ansi exam1.c -o test
Make sure your program compiles and works before your turn it in. We will not grade a program that does not
compile and you will lose points if the program compiles with warnings. You obviously will not receive any
points if your program does not do what it is supposed to do. Both functionality and coding style will be
graded, with most points given for functionality and some points given for style. No style grading will be done
if the program does not compile. Make sure that your output EXACTLY matches the specified structure and
example, including spacing and punctuation.
When you are finished, ensure the program compiles and then call the proctor.

Partial preview of the text

Download ECE 190 Midterm Exam 1 - Counting Primes and more Exams Introduction to Aerospace Engineering in PDF only on Docsity!

ECE 190 Midterm Exam 1

Spring 2011 Tuesday, February 15, 2011 In this assignment, you will need to write a program to count the number of primes less than n. A prime is a number that is not a multiple of any positive number other than 1 and itself. 1 is not a prime by definition. 2 is a prime because it is not divisible by any numbers other than 1 and itself; 4 is not a prime because it is divisible by 2, and so on. First, your program should ask the user "What is n? ". The user will reply with a positive integer n. You will compute the number of primes less than n and will provide the answer in the format "There are m primes less than n ." followed by a newline where m is the actual number of primes found and n is the number entered by the user. Sample run for your program when n is 191 should look like this: What is n? 191 There are 42 primes less than 191 You may NOT use any functions from math.h. To aid you in debugging or testing, here is a complete list of all 25 prime numbers between 1 and 100: 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 When you open a terminal do NOT type ece190. If you type ls in the terminal the output should include a skeleton file as well as a Makefile. If you do not see this, please contact a TA. The command make will compile your code, and the command make test will provide a basic functionality check. You are responsible for developing your own test cases, if need be. Name your program file exam1.c. You should compile your code either using make or as follows: gcc - g - Wall - Werror - ansi exam1.c - o test Make sure your program compiles and works before your turn it in. We will not grade a program that does not compile and you will lose points if the program compiles with warnings. You obviously will not receive any points if your program does not do what it is supposed to do. Both functionality and coding style will be graded, with most points given for functionality and some points given for style. No style grading will be done if the program does not compile. Make sure that your output EXACTLY matches the specified structure and example, including spacing and punctuation. When you are finished, ensure the program compiles and then call the proctor.