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 :: c++ struct constructor 
Cpp :: card validator c++ 
Cpp :: float to int c++ 
Cpp :: binary search c++ 
Cpp :: c++ string find example 
Cpp :: how to calculate bitwise xor c++ 
Cpp :: if statement c++ 
Cpp :: stack implementation through linked list 
Cpp :: C++ code for Dijkstra’s Algorithm 
Cpp :: Disabling console exit button c++ 
Cpp :: c++ Program to check if a given year is leap year 
Cpp :: check if element in dict c++ 
Cpp :: c++ initialize static variable 
Cpp :: check if a key is in map c++ 
Cpp :: c++ pre-processor instructions 
Cpp :: count number of prime numbers in a given range in c 
Cpp :: c for loop decrement 
Cpp :: C++ Integer Input/Output 
Cpp :: inheritance example in C plus plus 
Cpp :: dice combinations cses solution 
Cpp :: comparator priority queue c++ 
Cpp :: c++ uint8_t header 
Cpp :: google test assert stdout 
Cpp :: print fps sfml 
Cpp :: dequeue c++ 
Cpp :: how to concatinate two strings in c++ 
Cpp :: c++ list of pairs 
Cpp :: statements 
Cpp :: c++ if else example 
Cpp :: order 2d array in c++ 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =