Homework 1 Csc309.
Due Monday April 3, 2006 by 11:59pm.
Problem 1
(25 points)
From the Kalin text. Write a program that reads nonnegative integers and then outputs Yes if the numbers do not decrease and No otherwise. (The numbers do not decrease if, for every pair n1, n2 in succession, we have n1≤ n2.
Examples
If the input is ..
0 14 14 27 78
The output is .. yes
If the input is ..
0 3 1 7 29
The output is No
Assume a negative integer marks the end of the input.
Problem 2
25 points
Get the program primes.cpp. For practice, I would suggest typing in the code. For this problem instead of printing the primes to the console store them in a vector.
Next, traverse the vector and print a two column table showing all the twin primes less then or equal to the number that was input. Twin primes are two primes that differ by two. Ex ( 5, 7 and 17, 19 ).
Sample Run
Enter a positive integer: 49 Twin Primes 3 5 5 7 11 13 17 19 29 31 41 43
Turn in Instructions
Upload each problem to COL