Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in C++ and cannot hse any break statements A prime number is a number such that 1 and itself are the only numbers that evenly

in C++ and cannot hse any break statements
image text in transcribed
A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 2, 3, 5, 7, 11, 13, 17, 19, ...). Write a program that finds and prints all of the prime numbers between 2 and N (N is input from the user). Your program should also print the amount of prime numbers between 2 and N. For example, if N = 10 your program should print something like follows: There are 4 prime numbers between 2 and 10: 2, 3, 5, 7 To solve this problem use a doubly nested loop (a loop inside another loop). The outer loop can iterate from 2 to N while the inner loop checks to see if the current counter value for the outer loop is prime. To calculate whether number n is prime the program must loop from 2 to n-1 and if any of these numbers evenly divides n, then n cannot be prime. If none of the values from 2 to n-1 evenly divides n, then n must be prime. Note: You cannot use any "break" statements for this program

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

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago