answersLogoWhite

0

#include<iostream>

#include<cmath>

#include<utility>

bool is_prime (const unsigned n) {

if (n<2) return false;

if (!(n%2)) return n==2;

unsigned max_factor=(unsigned)sqrt((double)n)+1;

for (unsigned factor=3; factor<max_factor; ++factor) {

if (!(n%factor)) return false;

}

return true;

}

void print_primes(const unsigned low, const unsigned high) {

for (int i=low; i<=high; ++i) {

if (is_prime (i)) std::cout<<i<<std::endl;

}

}

int main () {

unsigned n, x;

std::cout<<"Print prime numbers\nFrom: ";

std::cin>>n;

std::cout<<"To: ";

std::cin>>x;

if (x<n) std::swap(x,n);

print_primes (n, x);

}

User Avatar

Wiki User

10y ago

What else can I help you with?

Continue Learning about Engineering

How do you print non-prime numbers in java?

Loop through some numbers - for example, 2 through 100 - and check each one whether it is a prime number (write a second loop to test whether it is divisible by any number between 2 and the number minus 1). If, in this second loop, you find a factor that is greater than 1 and less than the number, it is not a prime, and you can print it out.


What BASIC program can compute and display all prime numbers from 1 to 40?

PRINT 2,3,5,7,11,13,17,19,23,29,31,37


Python function that lists prime numbers?

If you just want a hint: One way to check whether a number is prime is by dividing it by any number between 2 and the square root of your number. If the number divides by any of these, it is not prime. If you want the code: import math for num in range(1,101): if all(num%i!=0 for i in range(2,int(math.sqrt(num))+1)): print num


Write a c program to find out the prime numbers between 1 to 500?

Here is a simple program to generate prime numbers upto a given specific number /*Prime No. from 1 to 50*/ /*By-Himanshu Rathee*/ #include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int i,j,n; clrscr(); printf(" Enter the number upto which we have to find the prime number: "); scanf("%d",&amp;n); printf("\n"); for(i=2;i&lt;=n;i++) { for(j=2;j&lt;=i-1;j++) if(i%j==0) break; /*Number is divisble by some other number. So break out*/ if(i==j) printf("\t%d",i); /*Number was divisible by itself (that is, i was same as j)*/ } /*Continue loop upto nth number*/ getch(); }


Is 38 a composite number?

Yes. All non-prime numbers are composite numbers, which simply means a number has one or more prime factors other than 1 and the number itself.

Related Questions

How many prime numbers between 1 and 8888888888888888888888888888888888888888888888?

To determine the number of prime numbers between 1 and 8888888888888888888888888888888888888888888888, we can use the Prime Number Theorem. This theorem states that the density of prime numbers around a large number n is approximately 1/ln(n). Therefore, the number of prime numbers between 1 and 8888888888888888888888888888888888888888888888 can be estimated by dividing ln(8888888888888888888888888888888888888888888888) by ln(2), which gives approximately 1.33 x 10^27 prime numbers.


Who is the inventor of prime numbers?

Mathematics, including prime numbers, is discovered, not invented.Systems and methods we use are invented, but concepts of relationships between objects governed by logic, such as the prime numbers are discovered and named. As such, a more appropriate question might be "Who discovered prime numbers?"Many have discovered prime numbers; the first is unknown to mankind.


How can print prime numbers in between 1-100 but not adjust 40-50 in php language?

Use a counted loop in the closed range [1:100]. If the count is in the closed range [40:50], print the number. For all other numbers outwith this range, only print the number if it is prime.


What is the product of the prime numbers between 29 and 30?

29 is a prime number. There are no prime numbers between 29 and 30.


Are there less prime numbers between 101 and 200 than between 1 and 100?

NO. There are more prime numbers between 1 and 100 than the prime numbers between 101 and 200.number of prime numbers between 1 and 100 = 25number of prime numbers between 101 and 200 = 20


What are the prime numbers between 33 and 36?

There are no prime numbers between 33 and 36.


Are there prime numbers between 114 and126?

There are no prime numbers between 114 and 126.


What are the prime numbers between 31 and 50?

The prime numbers between 31 and 50 are 37,41,43,47.


What are the prime numbers between 12 and 48?

The prime numbers between 12 and 48 are 13,17,19,23,29,31,37,41,43,47.


What are the prime numbers between 41 and54?

The prime numbers between 41 and 54 are 43,47,53.


How many prime numbers are in between 71 to 80?

Prime numbers between 71 to 80 = 73 and 79 Therefore there are 2 prime numbers between 71 to 80.


What is the sum of the prime numbers between 90 and 100?

The prime numbers between 90 and 100 are 97. To find the sum of prime numbers between 90 and 100, you simply add 97 to get the total sum. Therefore, the sum of prime numbers between 90 and 100 is 97.