How to solve Fizzbuzz Problem [Solved!]
jenni9 10 Aug 2018, 05:32
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
Murray 10 Aug 2018, 21:02
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>
You need to be logged in to reply.