Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise 8: Random integers (10 points) Write a program that generates a list of

ID: 3589603 • Letter: E

Question

Exercise 8: Random integers (10 points) Write a program that generates a list of 100 random integers in [O, 100), which means between O and 99 inclusive. Save the program output by redirecting the standard output stream to a file. To do this, run the program as follows. ./a.out >numbers.txt Open numbers.txt in a text editor to see the result. Exercise 9: Detecting prime numbers (10 points) Write a console program that asks the user to enter an integer greater than 1. The program determines if the number entered is prime and writes a message to standard output stream stating whether the number is prime or not. For example, if the user enters 42, the program displays "42 is not prime." If the user enters 47, the program displays "47 is prime." Be sure to test your program's output with 8 different numbers. It is important to test your program's output after compiling it to make sure that your code is correct. Document these test cases at the bottom of your code, showing the input and output of each. Example: result prime not prime prime 2 and so on

Explanation / Answer

Question 8


#include <iostream>
#include <cstdlib>   
#include <ctime>
using namespace std;

int main()
{
srand (time(NULL));
for( int i=0;i<100; i++) {
cout<<rand() % 100<<endl;
}
return 0;
}
Output:

Question 9


#include <iostream>
using namespace std;
bool isPrime(int n) {
for (int f = 2; f <= n / 2; f++) {
if (n % f == 0) {
return false;
}
  
}
return true;
}
int main()
{
int n;
cout<<"Enter the number: "<<endl;
cin >> n;
if(isPrime(n)) {
cout<<n<<" is a prime"<<endl;
} else {
cout<<n<<" is not a prime"<<endl;
}
return 0;
}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote