Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fizzbuzz changed #92

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions C++/fizzbuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,39 @@ Problem : a) print "FizzBuzz" ,if N (user input) is divisile to 3 and 5,
b) print "Fizz" ,if N (user input) is divisile to 3 ,
c) print "Buzz" ,if N (user input) is divisile to 5
*/
// There is no need of "for" loop to print output as you mentioned above.
//If it is not the way you want you can mention it again.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @MaxJaycee looping is required as you need to print the pattern of 1, 2, Fizz, 4, Buzz....

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i will try for it again.


#include <bits/stdc++.h>

using namespace std;

void printValue(int n)
{
for (int i = 1; i <= n; i++)
{
if(i%3 ==0 && i%5==0)
if(n % 3 ==0 && n % 5==0)
{
cout << "FizzBuzz ,";
cout << "FizzBuzz ";
}
else if (i % 3 == 0)
else if (n % 3 == 0)
{
cout << "Fizz ,";
cout << "Fizz ";
}
else if (i % 5 == 0)
else if (n % 5 == 0)
{
cout << "Buzz ,";
cout << "Buzz ";
}
else
{
cout << i << ", ";
}
if (i % 10 == 0)
{
cout << "\n";
cout << n <<".";
}
}
}

int main()
{
cout << "Enter a number:\n";

int n;
cin >> n;
cin >>n;
printValue(n);

return 0;
Expand Down