"On the white board, write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz"."
I don't have a white board, but this works too. Took me five minutes, works well to my knowledge
#include <iostream>
using namespace std;
int main() {
for (int a=1;a<=100;cout << endl, a++) {
if (((a % 3)==0) || ((a % 5)==0)) {
if ((a % 3)==0) cout << "Fizz";
if ((a % 5)==0) cout << "Buzz";
}
else cout << a;
}
system("pause>nul"); // holds execution window open, can easily be replaced
}

New Topic/Question
Reply



MultiQuote

|