#include <stdio.h>
int main (int argc, char **argv) {
int i, j, prime;
for (i=51; i<=99; i+=2) {
prime=1;
for (j=3; j<=i-2; j+=2) {
if (i%j == 0) {
prime=0;
break;
}
}
if (prime) printf ("%d ", i);
}
printf ("\n");
return 0;
}
Chat with our AI personalities
#include<iostream>
#include<vector>
bool is_prime (unsigned num) {
if (n<2) return false; // 0 and 1 are composite
if ((n % 2) 2; // 2 is the only even prime (all others are composite)
// test all odd divisors to see if any are factors of n
for (unsigned d=3; d<=(unsigned)sqrt(n); d+=2) {
if ((n % d) == 0) return false; // d is a factor of n so n is composite
}
return true; // if we get this far, n is prime
}
int main (void) {
std::vector<unsigned> primes;
for (unsigned n=1; n<=100; ++n) {
if (is_prime (n)) primes.push_back (n);
}
std::cout << "There are " << primes.size() << " prime numbers in the range 1 to 100\n";
// ... }
There are 25 prime numbers between 1 and 100.
They are: 2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 and 97.
The number 1 57 87 91 and 93 are prime.
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.
You need a code that can run to print even numbers between 10 and 100 using the qbasic command.
#include<stdio.h> #include<conio.h> void main() { int i,j; for(i=51;i<100;i=i+2) { printf("%d", i); } getch(); }
system.out.println(" print 1-100 numbers");for(i=0;i
wap to print all the arnstrong no. between 100&1000