Search IntMath
Close

450+ Math Lessons written by Math Professors and Teachers

5 Million+ Students Helped Each Year

1200+ Articles Written by Math Educators and Enthusiasts

Simplifying and Teaching Math for Over 23 Years

# How to solve Fizzbuzz Problem [Solved!]

### My question

Hello,

I'm trying to solve the fizzbuzz problem on interviewbit.com

Can someone help?

### Relevant page

FizzBuzz - InterviewBit

### What I've done so far

for(auto i=1; i<=A; i++)
{
if(i%3==0 && i%5==0)
v.push_back("FizzBuzz");

else if(i%3==0)
v.push_back("Fizz");

else if(i%5==0)
v.push_back("Buzz");

else
v.push_back(to_string(i));
}

return v;


X

Hello,

I'm trying to solve the fizzbuzz problem on interviewbit.com

URL: <a href="https://www.interviewbit.com/problems/fizzbuzz/">FizzBuzz - InterviewBit</a>

Can someone help?
Relevant page

<a href="https://www.interviewbit.com/problems/fizzbuzz/">FizzBuzz - InterviewBit</a>

What I've done so far

for(auto i=1; i<=A; i++)
{
if(i%3==0 && i%5==0)
v.push_back("FizzBuzz");

else if(i%3==0)
v.push_back("Fizz");

else if(i%5==0)
v.push_back("Buzz");

else
v.push_back(to_string(i));
}

return v;


## Re: How to solve Fizzbuzz Problem

I'm not a C++ user, but it looks OK to me. A suggestion:

Your first "if" could be simplified as:

if(i%15==0)

X

I'm not a C++ user, but it looks OK to me. A suggestion:

Your first "if" could be simplified as:

<pre>if(i%15==0)</pre>