4 ms·
Technically, this would be more efficient: #include <iostream> using namespace std; int main() { for (int i = 1; i <= 100; i++) { bool t =
by Metricon 8y ago
Technically, this would be more efficient:
#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <= 100; i++) {
bool t = (i % 3 == 0);
bool f = (i % 5 == 0);
if (!t && !f) { cout << i << endl; continue; }
if (t) cout << "Fizz";
if (f) cout << "Buzz";
cout << endl;
}
}
But most interviewers are interested in the basic logic of the process.