Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ fizzbuzz

// a short fizzbuzz, can make smaller by removing spaces
#include <iostream>

int i;
int main() {
for (auto &o=std::cout; ++i < 101; o<<'
')
    i%3? o :  o << "Fizz",
    i%5? i%3? o << i :o : o << "Buzz";
}
Comment

fizzbuzz c++

#include <iostream>
using namespace std;

void fizzBuzz(int n)
{
	for (int i = 1; i <= n; i++)
	{
		if (i % 3 != 0 && i % 5 != 0) //check if the number is neither a multiple of 5 nor 3
		{
			cout << i << endl;
		}
		else if (i % 3 == 0) //check if the number is a multiple of 3
		{
			if (i % 5 == 0) //check if the number is also a multiple of 5
			{
				cout << "FizzBuzz" << endl;
			}
			else
			{
				cout << "Fizz" << endl;
			}
		}
		else
		{
			cout << "Buzz" << endl; //if the number didn't satisfy the first if statement or the else if statement then it is a multiple of 5
		}
	}
}

int main()
{
	fizzBuzz(15);

	return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: string to long integer c++ 
Cpp :: print each number of digit c++ 
Cpp :: c++ random number between 0 and 1 
Cpp :: c++ multidimensional vector 
Cpp :: for loop in c++ 
Cpp :: c++ typing animation 
Cpp :: c++ enum 
Cpp :: C++ press enter to continue function 
Cpp :: when was c++ created 
Cpp :: all possible permutations of characters in c++ 
Cpp :: how to add an element to std::map 
Cpp :: destructor in c++ 
Cpp :: check if character in string c++ 
Cpp :: pop_back 
Cpp :: c++ structure 
Cpp :: c++ split string by several space 
Cpp :: c++ pause linux 
Cpp :: powershell get uptime remote computer 
Cpp :: string to integer in c++ 
Cpp :: find second highest number in c++ 
Cpp :: modulo subtraction 
Cpp :: factorial loop c++ 
Cpp :: classes and objects in c++ 
Cpp :: Sort html elements in Jquery on condition 
Cpp :: cpp class constructor 
Cpp :: c++ hello world linux 
Cpp :: print counting in c++ 
Cpp :: set width qpushbutton 
Cpp :: c++ program to convert character to ascii 
Cpp :: passing structure to function in c++ example 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =