1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Viefleur [7K]
3 years ago
9

Project 5: Prime Numbers. Write a program that reads in an integer that is greater than 2 (let's call it k) and finds and prints

all of the prime numbers between 3 and k. A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 3, 5, 7, 11, 13, 17, ...). One way to solve this problem is to use a doubly nested loop. The outer loop can iterate from 3 to k 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 divides !n, then n must be prime. (Note that there are several easy ways to make this algorithm more efficient.)
Computers and Technology
2 answers:
Blizzard [7]3 years ago
6 0

Answer:

#section 1

def is_prime_v1(n):

   for d in range(2, n):

       if n % d == 0:

           return False

   return True

#section 2

while True:

   try:

       num = int(input('Enter a number greater than 2: '))

       if num > 2:

           break

       else:

           raise

   except:

       print('{} is not greater than 2'.format(num))

#section 3

for n in range(3, num):

   is_prime_v1(n)

   a=is_prime_v1(n)

   if a==True:

       print (n)

Explanation:

The programming language used is Python 3.

#section 1

In this section we create a function that will check if a number is a prime number. The function returns True for prime numbers and False for normal numbers.

#section 2

In this section we make use of a WHILE loop and a try and except block to ensure that the input by the user is greater than two, if the input is less than 2, an exception is raised and the except block prompts the user to enter the appropriate value.

when the appropriate value is entered the loop breaks and the value is carried to the last section.

#section 3

In this final section, the value collected from the user in #section 2, is inserted as the upper-limit in a range function with the lower limit set at 3.

The function created in #section 1 is called and each value in the range is passed to it and an IF statement checks if the output is True or False. If the IF block evaluated to be True, it implies that the number is a prime number and the result is printed to the screen.

alexandr1967 [171]3 years ago
5 0

Answer:

#include <iostream>

using namespace std;

int main() {

   int k;

   cin>>k;

   cout<<"2 "; //printing the first prime number.

   for(int i=3;i<=k;i++)

   {

       int divisor=2;//divisor to check the prime numbers.

       while(divisor<i)

       {

           if(i%divisor==0)//if i is divisible by divisor then it is not prime.

           {

               break;

           }

           divisor++;

       }

       if(divisor==i)

       {

           cout<<divisor<<" ";

       }

   }

return 0;

}

Input:-

24

Output:-

2 3 5 7 11 13 17 19 23

Explanation:

The above-written code is in c++.It prints all the prime numbers upto the integer entered k.To achieve this I have nested loops for and while.For loop runs over 3 to n because 2 is a prime number so we are printing it beforehand.For every value of the for loop.It will be checked it is prime or not.If it is prime then the integer is printed else it is not printed.

You might be interested in
The purpose of multivariate analysis in index construction is to discover the simultaneous interaction of the items to determine
pychu [463]

Answer:

The answer is TRUE. It is a TRUE statement.

Explanation:

Multivariate analysis is the analysis of simultaneous interactions between several variables. If two items are very correlated, they could all be included in the same index.

7 0
3 years ago
How do I mirror cast my smart lg tv?​
lora16 [44]
I really wish I could help you but I don’t know
6 0
3 years ago
Client/server awareness. Visit three local stores in your neighborhood or mall and notice the information technology in the stor
Kaylis [27]

local stores in neighborhood do not have computerized cash registers but they may have cameras if they are in a bad neighborhood. inventory is controlled by checking the shelves.


the Qs about computers, servers and clients are for national chain stores. they use clients at each store which are connected to the central servers at HQ. employees need special training as the system is complicated. the whole system is maintained by their IT department.


7 0
3 years ago
Read 2 more answers
Percentage-wise, which renewable energy source is used most?
Natasha2012 [34]
C)Hydroelectric I believe.
5 0
3 years ago
Nila has created a report, and now she would like to a create table of contents. Nila has reviewed her report and decides to add
Alenkinab [10]

Answer:

The answer is "heading"

Explanation:

Headings, which appear into your document must be marked simply, objectively and correctly because it shows the final report structure and enable to easy access with specific information.  

  • It also promotes to read the document. So, its consistency is ensured in the headings.
  • In sort documents, it can't require any heading, but it Nila created a report, in which she requires  heading and then she update the content of the tables, and other choices can't be described in the given scenario, that's why it is correct
5 0
4 years ago
Other questions:
  • 1.
    13·1 answer
  • Say our confusion matrix is as follows, calculate precision, recall, and accuracy. Interpret the results for the positive class.
    10·1 answer
  • Which one of these tasks best describes the process of localization?
    12·1 answer
  • Which fingers should you use to type the reach keys?
    12·1 answer
  • Where is a 3D modeler most likely to work?
    6·1 answer
  • A power supply serves as both a rectifier and transformer to convert AC house current to DC and to step down voltage from 110 V
    6·1 answer
  • A customer is looking for a storage archival solution for 1,000 TB of data. The customer requires that the solution be durable a
    9·1 answer
  • Is iphone battery being draned if plugged into car charger when listening to podcasts
    6·1 answer
  • Describe psychographic differences among the past five generations of Americans that you learned about in this course. What type
    6·1 answer
  • Connect research concepts to their definitions
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!