-
Notifications
You must be signed in to change notification settings - Fork 3
/
Fizzbuzz_Challenge.cpp
52 lines (48 loc) · 1.25 KB
/
Fizzbuzz_Challenge.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
Write a program that prints the numbers from '1' to 'n' where value of 'n' is given by the user
and for multiples of '3' print "Fizz" instead of the number, for the multiples of '5' print "Buzz"
and for the numbers which are divisible by both '3' and '5' print "Fizzbuzz"
*/
#include<conio.h> // for getch() function
#include<iostream> // for standard input and output
using namespace std;
void fizzbuzz()
{
int n, i;
cout<<"\n Enter the number (enter value greater than '1'): ";
cin>>n; // taking input of max value to which loop will run
if(n) // to check the input value
{
cout<<"\n The series is : \n\n";
for(i=1;i<=n;i++)
{
if((i%3)==0 && (i%5)==0)
{
cout<<"Fizzbuzz"; // if the number is divisible by both 3 and 5 then "Fizzbuzz" will be printed
}
else if((i%3)==0)
{
cout<<"Fizz"; // if the number is divisible only by 3 and not by 5 then "Fizz" will be printed
}
else if((i%5)==0)
{
cout<<"Buzz"; // if the number is divisible only by 5 and not by 3 then "Buzz" will be printed
}
else
{
cout<<i;
}
cout<<" ";
}
}
else
{
cout<<"\n\t Wrong Input !!!";
}
}
int main()
{
fizzbuzz();
getch();
return 0;
}