0 Replies - 66 Views - Last Post: 14 June 2008 - 09:15 AM

#1 polymath   User is offline

  • D.I.C Addict
  • member icon

Reputation: 54
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Fizz Buzz Interview Question

Posted 14 June 2008 - 09:15 AM

Description: See Above. Could be used for an interview, as per thread in corner cubicle:)Quote from skyhawk133:

"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
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1