Question

Create a program on C++ for finding all primes number between two values (inclusive) as sample...

Create a program on C++ for finding all primes number between two values (inclusive) as sample below

Sample Input Sample Output
1 10

2

3

5

7

11 20

11

13

17

19

30 40

31

37

NOTES: Please use ARRAY. please show me the code & results. the result must be exactly the same as above, no additional sentences or other stuff. thank you very much

Homework Answers

Answer #1

Explanation:

here is the program which expects 2 numbers entered by the user and then in that range, it checks whether each number is a prime number or not.

And then all the prime numbers are printed on the screen.

Code:


#include <iostream>

using namespace std;

int main()
{
int a, b;
cin>>a>>b;
  
for (int i = a; i <=b; i++) {
  
int is_prime = 1;
  
for (int j = 2; j<i; j++) {
  
if(i%j==0)
{
is_prime=0;
}
}
  
if(i==1)
{
is_prime=0;
}
  
if(is_prime==1)
{
cout<<i<<endl;
}
}

return 0;
}

output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

PLEASE COMMENT IF YOU NEED ANY HELP!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using nested loops, write a function called primes(a,b) that takes in two positive integers a and...
Using nested loops, write a function called primes(a,b) that takes in two positive integers a and b (where a<b). Then simply RETURNS a string containing all the prime numbers between a and b (or if there are none, the string "No Primes"). You should check that a and b are valid inputs, that is, that a and b are integers such that a<b (otherwise, the function should print “No Primes”). Three sample calls of your function (in IDLE) should produce...
Create a C Program called Summer_Heat that meets the following criteria: Lines 1,2: Identifies the name...
Create a C Program called Summer_Heat that meets the following criteria: Lines 1,2: Identifies the name of Program that the Programmer Lines 4,5: Includes the header files to allow input and output and use the system commands Line 7: Includes Declarations comment Line 8: Declares counter as an integer with an initial value of 0 Line 9: Initializes a double array called temperature using a single statement and the following 10 values 78.6 82.1 79.5 75.0 75.4 71.8 73.3 69.5...
Write a C++ program that processes orders for our company Widgets and More. Your program will...
Write a C++ program that processes orders for our company Widgets and More. Your program will read the product code and quantity for all the products in an order from a file, order.txt. You will be given a sample order.txt with the starter code. There are two items on each line of the file the first is a letter that represents the product and the second is an integer representing the number bought. Based on the product and quantity, you...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will...
Program will allow anywhere between 1 and 6 players (inclusive). Here is what your output will look like: Enter number of players: 2 Player 1: 7S 5D - 12 points Player 2: 4H JC - 14 points Dealer: 10D Player 1, do you want to hit? [y / n]: y Player 1: 7S 5D 8H - 20 points Player 1, do you want to hit? [y / n]: n Player 2, do you want to hit? [y / n]: y...
And need to be writing in C++ language Programm need to start with   #include<fstream> Prepare a...
And need to be writing in C++ language Programm need to start with   #include<fstream> Prepare a text file data_in.txt with the following information (highlight the piece of text below with numbers and copy it to a text file): 54, 70, 75, 63, 17, 59, 87, 16, 93, 81, 60, 67, 90, 53, 88, 9, 61, 8, 96, 98, 12, 34, 66, 76, 38, 55, 58, 27, 92, 45, 41, 4, 20, 22, 69, 77, 86, 35, 19, 32, 49, 15,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21,...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21, all players who are still standing win. But the players that are not standing have already lost. If the Dealer does not go over 21 but stands on say 19 points then all players having points greater than 19 win. All players having points less than 19 lose. All players having points equal to 19 tie. The program should stop asking to hit if...
Q1. Use Union statements to show the following: list the number of artists that have a...
Q1. Use Union statements to show the following: list the number of artists that have a webaddress, the number of artists that do not have a webaddress, and the total number of artists. The output should look like: +--------------------------+----------+ | Has webaddress | count(*) | +--------------------------+----------+ | Has webaddress | 5 | | Does not have webaddress | 6 | | Total | 11 | +--------------------------+----------+ Q2. A new salesperson has been hired. Their SalesID is 5, full name is...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT