Skip to main content
Search IntMath
Close

IntMath forum | Systems of Equations

How to solve Fizzbuzz Problem [Solved!]

My question

Hello,

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

URL: FizzBuzz - InterviewBit

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>

Reply

You need to be logged in to reply.

Related Systems of Equations questions

Systems of Equations lessons on IntMath

top

Tips, tricks, lessons, and tutoring to help reduce test anxiety and move to the top of the class.