Question

(prime.cpp) A prime number is a number that cannot be formed by multiplying two smaller numbers (not including 1). For exampl

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;
// Function to check the given number is prime or not
bool isprime(int n)
{
if(n<2) return false;
for(int i=2;i<n;i++)
{
if(n%i==0)
return false;
}
return true;
}
int main()
{
int start,end,t;
cout<<"Enter the start point: ";
cin>>start;
cout<<"Enter the number of prime numbers: ";
cin>>end;
cout<<"Enter how many numbers to display per row: ";
cin>>t;
cout<<"The prime numbers from "<<start<<" to "<<end<<" are: "<<endl;
int k=0; // It is used to change the line after every t element
for(int i=start;i<=end;i++)
{
if(isprime(i))
{
    cout.width(5);
cout<<i<<" ";
k++;
if(k==t)
{
k=0;
cout<<endl;
}
}
}
return 0;
}

main.cpp #include<iostream> 2 using namespace std; 3 // Function to check the given number is prime or not 4 bool isprime(intEnter the start point: 1 Enter the number of prime numbers: 100 Enter how many numbers to display per row: 10 The prime numbe

Add a comment
Know the answer?
Add Answer to:
(prime.cpp) A prime number is a number that cannot be formed by multiplying two smaller numbers...
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
  • Source: 2014 Nielsen 72 Prime Numbers A prime number is a number that is evenly divisible...

    Source: 2014 Nielsen 72 Prime Numbers A prime number is a number that is evenly divisible only by 1 and itself. The prime numbers less than 100 are listed below. 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 Choose one of these numbers at random. Find the probability that a. The number is odd b. The sum of the digits is odd c....

  • Using Python: A Prime number is an integer greater than 1 that cannot be formed by...

    Using Python: A Prime number is an integer greater than 1 that cannot be formed by multiplying two smaller integer other than 1 and itself. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1. In this question you will write a program that takes a sequence of integers from the user and display all the prime numbers contained in that sequence. We will separate this question in...

  • The task involves writing a C++ program that determines the prime numbers between 1 and 100....

    The task involves writing a C++ program that determines the prime numbers between 1 and 100. The steps you should follow to identify the prime numbers are the following. 1. The number 1 is not a prime number, so it should be scratched. 2. Starting from the first prime number, which is 2, you scratch all the numbers that are the multiple of 2. You should not scratch out 2 itself. 3. The next number in the sequence after the...

  • 4. Write a logical function perfect Square that receives a positive integer number and checks if ...

    write the code in C please 4. Write a logical function perfect Square that receives a positive integer number and checks if it is a perfect square or not. Note: perfect square numbers are 4, 9,16,25,36 etc.... Write a main function that makes use of the perfect Square function to find and print all perfect squares between nl and n2. nl and n2 are end values of a range introduced by the user. ■ (inactive CAT EXE) Enter end values...

  • USE PYTHON PLEASE Write a function called is prime which takes a single integer argument and...

    USE PYTHON PLEASE Write a function called is prime which takes a single integer argument and returns a single Boolean value representing whether the given argument is prime (True) or not (False). After writing the function, test it by using a loop to print out all the prime numbers from 1-100. To check your results, the prime numbers from 1-100 are: 2, 3, 5, 7, 11. 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,...

  • Using python Part 3c: Custom Number Range Make a copy of Part B and update it...

    Using python Part 3c: Custom Number Range Make a copy of Part B and update it so that the user can choose to examine a specific range of numbers for prime numbers. Here's a sample running of your program: Start number: 5 End number: -5 Start and end must be positive Start number: 5 End number: 3 End number must be greater than start number Start number: 5 End number: 23 5 7 11 13 17 19 23 Part 3d:...

  • A prime number is a natural number greater than 1 that cannot be formed by multiplying...

    A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1, involve 5 itself. Design and implement a NAND-only circuit that detects all the prime number from 0 to 7 (with zero included). You may use NOT gates (inverters) to invert the inputs alone, not the outputs. Fill out...

  • *** Write a function called circular_primes that finds the number of circular prime numbers smaller than...

    *** Write a function called circular_primes that finds the number of circular prime numbers smaller than n, where n is a positive integer scalar input argument. For example, the number, 197, is a circular prime because all rotations of its digits: 197, 971, and 719, are themselves prime. For instance, there are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97. It is important to emphasize that rotation means circular...

  • CODE MUST BE WRITTEN IN SWIFT programming language Write a function that takes in two positive...

    CODE MUST BE WRITTEN IN SWIFT programming language Write a function that takes in two positive integers and prints every prime number between (and including) them Sample Input: prime(from: 0, to: 100) Sample Output: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

  • 17. Prime Numbers A prime number is a number that is only evenly divisible by itself...

    17. Prime Numbers A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and S. The number 6, how- ever, is not prime because it can be divided evenly by 1, 2, 3, and 6. Write a Boolean function named is_prime which takes an integer as an argument and returns true if the argument is a prime number, or...

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