## Question

1) List of prime numbers Recall: a prime number is a number (greater than 1) that is only divisible by itself and 1. Write a program that prompts the user to enter a number (greater than or equal to 2). The program should then output all the primes between 1 and the number. Your program should include a function that determines if a number is prime.

2) What day of the year is it? Write a program that takes the date (in month-day-year format) and outputs the day number of the year. For instance, if the user enters 1-1-2015, the day number is 1. The program should check for a leap year. A year is a leap year if it is divisible by 4 but not divisible by 100 (e.g. 2004, 1996). However a year that is divisible by 100 is also a leap year if it is also divisible by 400 (e.g. 2000). Your program should include a function to determine the day as well as a function to check for leap years.

Extra: Reverse digits Write a program that takes an integer and outputs the reverse of an integer. For instance, if the user enters 65, the program should output 56. Your program should include a function that performs the reversal.

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdio.h>#include <vector>

using namespace std;

int readPrime() {

int n;

printf("please enter a prime number: ");

scanf("%d", &n);

return n;

}

vector<int> returnPrimes(int n) {

int start_val = 2;

vector<int> primes;

primes.push_back(1);

while (start_val <= n) {

while ((n % start_val) == 0) {

n/= start_val;

primes.push_back(start_val);

}

start_val+= 1;

}

return primes;

}

void printPrimes(int number) {

int vt = 0;

vector<int> primes = returnPrimes(number);

vector<int>::iterator v = primes.begin();

while( v != primes.end()) {

if (*v != vt) {

printf("%d ", *v);

}

vt = *v;

v++;

}

printf("\n");

}...

By purchasing this solution you'll be able to access the following files:

Solution.zip.