+ 3

Just and only prime numbers such as 1,3,5,7,11,13,17,21,23,27,31,33,37,41,.....till..97

Which loop

20th May 2018, 12:54 PM
Mahendra Kumar
Mahendra Kumar - avatar
5 Respuestas
20th May 2018, 1:36 PM
Rahul George
Rahul George - avatar
+ 4
#include <iostream> #include <vector> using namespace std; template<typename T> void removeVectorElement(std::vector<T> &vec, unsigned int at){ if(at == 0) vec.erase(vec.begin()); else vec.erase(vec.begin() + at); } int main() { std::vector<int> vec_prime; int maxPrimeNumber; cout << "Enter the number of prime up to: "; cin >> maxPrimeNumber ; cout << maxPrimeNumber << endl; for (int s = 2; s <= maxPrimeNumber; s++) vec_prime.push_back(s); for (int prime : vec_prime){ for (int i = 0; i < vec_prime.size(); i++){ if (vec_prime[i] % prime == 0 && prime != vec_prime[i]){ removeVectorElement(vec_prime, i); } } } cout << endl << "The prime numbers are: " << endl; for (auto d : vec_prime) cout << d << " "; cout << endl; return 0; }
20th May 2018, 1:26 PM
Víctor
Víctor - avatar
+ 2
مفيش حد مصري هنا ساعدونا يا جماعه
21st May 2018, 2:30 PM
Ahmed Khaled
+ 1
for loop
20th May 2018, 2:28 PM
E_E Mopho
E_E Mopho - avatar