Fizz and Buzz program is most conman program asked in interview for companies like QuickHeal etc.
The programming logic is simple, Consider it as like this
if 1 then A
else if 2 then B
else if 3 then C
else/otherwise D
So we can create pseudo code like this
if (the Number is divisible by 3) then
print "Fizz"
else if (the Number is divisible by 5) then
print "Buzz"
else /* the Number is not divisible by 3 and 5 */
print FizzBu
end if
Thats it .... Its that simple ... formatting and creating a proper code like
// inside Void Main () or any other programming convert it to respective constraint.
for (int i = 1; i <= 100; i++)
{
if (i % 15 == 0) //check if number in position i is divisable by 15, if so don't check other 2 conditions - we don't want a double print
{
cout << "fizz Buzz"< }
else if (i % 3 == 0 )
{
cout << "buzz"< }
else if (i % 5== 0)
{
cout << "fizz"< }
}
The programming logic is simple, Consider it as like this
if 1 then A
else if 2 then B
else if 3 then C
else/otherwise D
So we can create pseudo code like this
if (the Number is divisible by 3) then
print "Fizz"
else if (the Number is divisible by 5) then
print "Buzz"
else /* the Number is not divisible by 3 and 5 */
print FizzBu
end if
Thats it .... Its that simple ... formatting and creating a proper code like
// inside Void Main () or any other programming convert it to respective constraint.
for (int i = 1; i <= 100; i++)
{
if (i % 15 == 0) //check if number in position i is divisable by 15, if so don't check other 2 conditions - we don't want a double print
{
cout << "fizz Buzz"<
else if (i % 3 == 0 )
{
cout << "buzz"<
else if (i % 5== 0)
{
cout << "fizz"<
}
0 comments:
Post a Comment
Thanks for your Valuable comment