Starting from:
$30

$24

Homework 4 Solution

Files to submit: primes.c

Time it took Matthew to Complete: 15 mins




All programs must compile without warnings when using the -Wall and -Werror options



Submit only the files requested



Do NOT submit folders or compressed files such as .zip, .rar, .tar, .targz, etc



Your program must match the output exactly to receive credit.



Make sure that all prompts and output match mine exactly.



Easiest way to do this is to copy and paste them



All input will be valid unless stated otherwise



Print all real numbers to two decimal places unless otherwise stated



The examples provided in the prompts do not represent all possible input you can receive.



All inputs in the examples in the prompt are underlined



You don't have to make anything underlined it is just there to help you differentiate between what you are supposed to print and what is being given to your program
If you have questions please post them on Piazza



Restrictions




No global variables are allowed



Your main function may only declare variables, call other functions, and assign variables values.
The array you create to store your variables should only be long enough to fit only the primes that you are displaying
You should not have a limit on how large N can go for this problem
For this program you will be finding all of the prime numbers between 2 and N (inclusive). Remember that a number is prime if it is only evenly divisible by itself and 1.




Assumptions

1. Input may not be valid




Hints

1. It might be easier to consider what make a number not prime for this problem.




Examples

Enter a number greater than 1: 25 The primes between 2 and 25 are: 2 3 5 7 11 13 17 19 23




































Enter a number greater than 1: cat
Enter a number greater than 1: dog

Enter a number greater than 1: 1

Enter a number greater than 1: -2

Enter a number greater than 1: 100 The primes between 2 and 100 are: 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

More products