write a C++ program that display a prime numbers between 1 and 100 number. Plase print the remaining primes by “dots” For gexample The output should appear like
The prime numbers between 1 and 100 are: 1, 2, 3, 5, 7, .........
#include <iostream> using namespace std; bool checkPrime(int num) { int i; if (num <= 1) return 0; if (num % 2 == 0 && num > 2) return 0; for (i = 3; i < num / 2; i += 2) { if (num % i == 0) return false; } return true; } void primes(int n){ cout<<"The prime numbers between 1 and "<<n<<" are: "; for(int i = 2;i<=n;i++){ if(checkPrime(i)){ cout<<i<<", "; } } } int main(){ int n; primes(100); cout<<"........."<<endl; return 0; }
The prime numbers between 1 and 100 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, 97, .........
Get Answers For Free
Most questions answered within 1 hours.