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

6. Create a new program D1_Prog6. Topicis): Loops. a) Request a min and max valu

ID: 3729484 • Letter: 6

Question

6. Create a new program D1_Prog6. Topicis): Loops. a) Request a min and max value. b) Countdown and output all numbers from max to min inclusive. 7. Create a new program Di Prog7. Topic(s):Loops a) Request a number and an exponent. b) Calculate the number to the exponent power and display the answer For example, Number-2 and exponent 3, calculate 23 and display 8. Create a new program D1_Prog8. Topic(s): Sentinel loops, input validation. a) Request a positive integer. b) Infinitely repeat the request until -1 is entered. c) Sum all entered numbers (aside from the sentinel value (-1)) d) Output the sum to console. 9. Create a new program D1 Prog9,. Topic(s): Loops, algorithmic efficiency. a) Request a positive integer. b) Determine if the number is prime. - a prime number is only divisible by 1 and itself - loop should be optimized for maximum efficiency

Explanation / Answer

// D1_Prog6

// Topic(s) : Loops

#include <iostream>

using namespace std;

int main()

{

int minValue;

int maxValue;

cout << "Please enter min value ";

cin >> minValue;

cout << "Please enter max value ";

cin >> maxValue;

if(maxValue > minValue)

{

cout<<"Numbers are"<<endl;

int count = 0;

  

while(maxValue >= minValue)

{

cout << maxValue<<" ";

maxValue--;

count++;

}

cout<<endl;

cout<<"Total numbers = "<<count;

}

else

{

cout << "min is greater then max";

}

return 0;

}

// D1_Prog7

// Topic(s) : Loops

#include <iostream>

using namespace std;

int main()

{

int number, exponent, answer= 1;

cout << "Please enter number ";

cin >> number;

cout << "Please enter exponent ";

cin >> exponent;

while(exponent != 0)

{

answer = answer*number;

exponent--;

}

cout<<"Answer is "<< answer;

return 0;

}

// D1_Prog8

// Topic(s) : Sentinel loops, input, validation

#include <iostream>

using namespace std;

int main()

{

int number, sum = 0;

while(true)

{

cout << "Please enter positive number, -1 to finish entering ";

cin >> number;  

  

if(number == -1)

{

break;

}

else

{

sum = sum + number;

}

}

cout<<"Sum is "<< sum;

return 0;

}

// D1_Prog9

// Topic(s) : Loops, algorithmic efficiency

#include <iostream>

using namespace std;

int main()

{

int number,i;

bool prime = true;

cout << "Enter a positive integer: ";

cin >> number;

for(i = 2; i <= number / 2; ++i)

{

if(number % i == 0)

{

prime = false;

break;

}

}

  

if (prime)

cout << "Entered number is prime";

else

cout << "Entered number is not prime";

return 0;

}

// Please provide feedback thumbs up

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