Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. Primes Write a program that finds and prints all of the prime numbers between 3 and 100. A prime number is a number such

3. Primes

Write a program that finds and prints all of the prime numbers between 3 and 100. A prime number is a number such that one and itself are the only numbers that evenly divide it (e.g., 3,5,7,11,13,17, …). In additional to list all prime numbers in the specified range, you also need to find the largest gap number subtract between two immediately primes. For example, 11-7=4, 13-11=2, 17-13=4 where largest gap number is 4.

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 if the counter value for the outer loop is prime. One way to see if number n is prime is to 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 divide n, then n must be prime. (Note that there are several easy ways to make this algorithm more efficient).

c++

Step by Step Solution

3.43 Rating (166 Votes )

There are 3 Steps involved in it

Step: 1

Answer Source Co... 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

Introduction to Java Programming, Comprehensive Version

Authors: Y. Daniel Liang

10th Edition

133761312, 978-0133761313

More Books

Students also viewed these Electrical Engineering questions

Question

How would you respond to each of the girls?

Answered: 1 week ago