Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Objectives: Become familiar with C++ syntax. Become familiar with calculations using C++ programming language. Become familiar with if statements and for loops. Instructions ()

C++

Objectives:

Become familiar with C++ syntax.

Become familiar with calculations using C++ programming language.

Become familiar with if statements and for loops.

Instructions ():

Translate the pseudo code for the following problem into a runnable C++ program.

Upload the VS solution to the lab #3 to the appropriate drop box.

This problem can be found on page 96 #4 it is reproduced here for your convenience. The pseudo code is not in the book.

Write a program that finds and prints all prime numbers between 3 and 100. Please put a space in between each number. A prime number is a number that can only be divided by one and itself (i.e., 3,5,7,11).

One way to solve this problem is to use a doubly-nested loop. The outer loop can iterate from 3 to 100, while the inner loop checks to see whether the counter value for the outer loop is prime. One way to decide whether the number n is prime is to loop from 2 to n-1; if any of those numbers evenly divides n, the n cannot be prime. If none of the values from 2 to n-1 evenly divide n, then n must be prime. (Note that there are several easy ways to make this algorithm more efficient).

The following pseudo is a solution to the problem. You must translate this pseudo code into a runnable C++ program.

Pseudo Code:

Create a variable for a divisor Count with an initial value of 0

Loop from 3 to 100 inclusive control xIf x is not an even number Loop from 3 to 100 inclusive control yIf y is less than or equal to xIf x divided by y has no remainder

Increment divisor count by 1

If divisor count is greater than 1

Exit the y control loopnot a prime number

If the divisor count is less than 2

Print out the number as it is prime

Reset the divisor Count for next x value

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

Which team solution is more likely to be pursued and why?

Answered: 1 week ago

Question

Did the team members feel that their work mattered

Answered: 1 week ago