Question

   use C++ language Output the prime numbers between 1 and 1000 Ask the user for...

   use C++ language

  1. Output the prime numbers between 1 and 1000
  2. Ask the user for a color. If they choose "red", use a while loop to output "red" 5 times. If they choose "green", output "green" seven times with a for loop. If they choose anything else, tell them to choose a better color.
  3. Create a random number between 1 and 6
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1:

#include <iostream>

using namespace std;

//checks and returns true if given num is prime

bool isPrime(int aI) {

    for (int i = 2; i < aI; i++)

      if (aI % i == 0)

        return false;

    return true;

  }

int main(){

//iterating from 1-1000

  for(int i=1;i<1000;i++){

    if(isPrime(i)){

      cout<<i<<" ";

    }

    

  }

  

return 0;

}

Answer 2:

#include <iostream>

using namespace std;

int main(){

string str;

cout<<"Choose color: ";

cin>>str;

int i=0;

if(str=="green"){

while(i++<5)

cout<<"green"<<endl;

}

else if(str=="red"){

for( i=0;i<7;i++)

cout<<"red"<<endl;

}

else{

cout<<"Choose better color:";

}

return 0;

}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Answer 3:

#include <iostream>
#include <stdlib.h>
#include<time.h>
using namespace std;
// Driver program
int main(void)
{
// Use current time as seed for random generator
srand(time(0));
//generating random number between 1-100
cout<<rand()%6+1;
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
   use C++ language Output the prime numbers between 1 and 1000 Ask the user for...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  •    use C++ language Create a random number between 1 and 100 Ask the user for...

       use C++ language Create a random number between 1 and 100 Ask the user for their age. Use a while loop to ensure they give you a number between 20 and 50 Give the user five chances to guess the secret password "PASSWORD". If they don't guess it, tell them they do not have access.

  • In c# create a program that generates a random number from 1 to 1000. Then, ask...

    In c# create a program that generates a random number from 1 to 1000. Then, ask the user to guess the random number. If the user's guess is too high, then the program should print "Too High, Try again". If the user's guess is too low, then the program should print "Too low, Try again". Use a loop to allow the user to keep entering guesses until they guess the random number correctly. Once they figure it, congratulate the user....

  • ​Declare an array with 1000 elements of type int Then in a loop generate 1000 random numbers and assign one to each element in the array The random numbers should be between 1 and 50 Then, prompt the user to enter a number, store this number in a local

    Rules to follow are:Declare an array with 1000 elements of type intThen in a loop generate 1000 random numbers and assign one to each element in the arrayThe random numbers should be between 1 and 50do not use rand or srand, use code is providedThen, prompt the user to enter a number, store this number in a local variable, the number should be safety checked using the GetInteger() functionThen, iterate through the array and determine how many times the user's...

  • Guess the number! You will create a program that will ask the user to guess a...

    Guess the number! You will create a program that will ask the user to guess a number between 1 and 10. The pseudocode is below. Be sure to import random at the beginning of your code and use a comment block explaining what your program does #Guess the number week 4 #Name: #Date: #Random number, loop while true #ask user for number. #if number is too high or too low, tell user, if they guessed it break out of loop...

  • **Using C Language** Get a number from the user and use that number for loops and...

    **Using C Language** Get a number from the user and use that number for loops and to make some calculations. Get a number from the user (n) (For example if the user enters a 3, each loop below will repeat 3 times) //ask, get, and return an integer (by reference) void GetIntPointer(int *numPtr); //input: the number entered by the user (pass by copy) //Calculates the product of the first (n)numbers using a while loop and store the result in *productPtr...

  • Assignment Develop a program to analyze one or more numbers entered by a user. The user...

    Assignment Develop a program to analyze one or more numbers entered by a user. The user may enter one or more numbers for analysis. Input should be limited to numbers from 1 through 1000. Determine if a number is a prime number or not. A prime number is one whose only exact divisors are 1 and the number itself (such as 2, 3, 5, 7, etc.). For non-prime numbers, output a list of all divisors of the number. Format your...

  • C++ language Write a program that 1. generates a random integer between 100 and 1000, call...

    C++ language Write a program that 1. generates a random integer between 100 and 1000, call the number N 2. reads a file name from the keyboard 3. opens a file for output using the file name from step 2 4. generates N random numbers between 1 and 100 and writes them to the file from step 3 5. closes the file 6. opens the file from steps 3, and 4 for input 7. reads the numbers from the file...

  • Using C++ 1. Create a while loop that counts even numbers from 2 to 10 2....

    Using C++ 1. Create a while loop that counts even numbers from 2 to 10 2. Create a for loop that counts by five (i.e. 0, 5, 10, ...) from 0 to 100 3. Ask for a person's age and give them three tries to give you a correct age (between 0 and 100) 4. Use a for loop to list Celsius and Fahrenheit temperatures. The "C" should be from -20 to 20 and the F should be shown correspondingly...

  • Labview question: Create a VI using a While Loop that continuously generates random numbers between 0...

    Labview question: Create a VI using a While Loop that continuously generates random numbers between 0 and 1000 until it generates a number that matches a number selected by the user. Determine how many random numbers the VI generated before the matching number. conditions to applied on above problem: 1. Convert the “random number” generator floating point numerical output to integer values to make it easier to find a match. 2. The “user selected number control” should be on the...

  • Program Requirements First, find all the prime numbers between 2 and a user-inputted number from the...

    Program Requirements First, find all the prime numbers between 2 and a user-inputted number from the console (inclusive). The identified prime numbers must be stored in an array . The inputted number should be between 0 and 1000 (inclusive). array is large enough to o Make sure your hold all the prim e numbers. Dynamic memory allocation is not required for this assignment, so you can have unused space in your array Make sure you can handle the cases of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT