Skip to main content

IntMath Home » Forum home » Systems of Equations » How to solve Fizzbuzz Problem

IntMath forum | Systems of Equations

How to solve Fizzbuzz Problem [Pending...]

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.

Search IntMath, blog and Forum

Search IntMath