Untitled
unknown
plain_text
2 years ago
880 B
20
Indexable
Never
#include <iostream> int main() { int a[100]; int sizeArray = sizeof(a) / sizeof(int); int mul; sizeArray = sizeArray - 2; // loop until all the multiples are listed false, numbers that are not multiples will be left alone. for (int i = 2; i <= sizeArray; i++) { for (int j = 2; j <= sizeArray; j++) { mul = i * j; if (mul <= sizeArray) { a[mul] = false; } } } // loop to convert all the booleans to prime numbers and print them for (int i = 0; i <= sizeArray; i++) { if (i == 0 || i == 1) { std::cout << i << std::endl; continue; } if (a[i] != false) { for (int j = 0; j <= i; j++) { std::cout << "-"; } std::cout << i << std::endl; } else { std::cout << i; for (int j = 0; j <= i; j++) { std::cout << " "; } std::cout << "\\" << std::endl; } } }