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
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