answersLogoWhite

0

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

}

User Avatar

Wiki User

13y ago

Still curious? Ask our experts.

Chat with our AI personalities

JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao
More answers

#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";

// ... }

User Avatar

Wiki User

8y ago
User Avatar

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.

User Avatar

Wiki User

15y ago
User Avatar

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

User Avatar

Wiki User

10y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Print prime numbers between 1 to 100?
Write your answer...
Submit
Still have questions?
magnify glass
imp