Question #16317

2. a prime integer number is one that has exactly two different divisors, namely 1 and the number itself. Write, run and test a c++ program that finds all the prime numbers less than 100. (hint. 1 is a prime number. for each number from 2 to 100, find remainder = number % n, where n ranges from 2 to sqrt(number). if n is greater than sqrt (number), the number is not equally divisible by n. why? if any remainder equals 0, the number is not a prime number.

Expert's answer

#include<iostream>

using namespace std;

int isprime(int valuex){

int x,j;

x=1;

& for (j=2 ; j<valuex; j++)

{ if ((valuex%j)==0) x=0; }

& if(x!=0) return 1;

& else return 0;

}

void main(){

for (int i=1; i<101; i++)

& if (isprime(i)) cout<<i<<"\n";

system("pause");

}

using namespace std;

int isprime(int valuex){

int x,j;

x=1;

& for (j=2 ; j<valuex; j++)

{ if ((valuex%j)==0) x=0; }

& if(x!=0) return 1;

& else return 0;

}

void main(){

for (int i=1; i<101; i++)

& if (isprime(i)) cout<<i<<"\n";

system("pause");

}

## Comments

## Leave a comment