• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to secondary sidebar

GoHired

Interview Questions asked in Google, Microsoft, Amazon

Join WeekEnd Online Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

  • Home
  • Best Java Books
  • Algorithm
  • Internship
  • Certificates
  • About Us
  • Contact Us
  • Privacy Policy
  • Array
  • Stack
  • Queue
  • LinkedList
  • DP
  • Strings
  • Tree
  • Mathametical
  • Puzzles
  • Graph

FizzBuzz Solution C C++

May 19, 2015 by Dhaval Dave

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”. Print a new line after each string or number.
Here is C and C++ solutions

Fizz Buzz C Solution :

#include <stdio.h>
#define gc getchar_unlocked
#define pc putchar_unlocked
inline int scan(){register int n=0,c=gc();while(c<'0'||c>'9')c=gc();while(c<='9'&&c>='0')n=(n<<1)+(n<<3)+c-'0',c=gc();return n;} 
int printFB(int n){
 int i,j;
 for(i=1;i<=n;i++){
  if(i%3==0 && i%5==0)printf("FizzBuzz\n");
  else if(i%3==0)printf("Fizz\n");
  else if(i%5==0)printf("Buzz\n");
  else printf("%d\n",i);
  }
}
int main(void) {
 int t,n;
 t=scan();
   while(t--){
   n=scan();
   printFB(n);
   }
 return 0;
}

Fizz Buzz C++ Solution

#include <iostream>
using namespace std;
 
int main()
{
 int T,num, i=1;;
 cin >> T;
   while(T > 0) {
   cin>>num;
   cout<<"number="<<num<<"T="<<T<<endl;
   i=1;
      while(i<=num){
      if( i%15 == 0) {
      cout << "FizzBuzz" << endl; 
      }
      else if(i%5 == 0 ){
      cout << "Buzz" << endl; 
      }
      else if(i%3 == 0) {
      cout << "Fizz" << endl;
      }
       else {
       cout<<i<< endl;
       }
   i++;
   }
 T--;
 }
return 0;
}

Similar Articles

Filed Under: Adobe Interview Questions, Hacker Earth Questions, Interview Questions, Microsoft Interview Questions, problem Tagged With: c, Mathematical

Reader Interactions

Trackbacks

  1. Urban Ladder Written Test. - GoHired says:
    May 19, 2015 at 7:44 pm

    […] 1 ) Print Fizz Buzz  […]

Primary Sidebar

Join WeekEnd Online/Offline Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

Join WeekEnd Online/Offline Batch from 4-April-2020

WhatsApp us

Secondary Sidebar

Custom Search

  • How I cracked AMAZON
  • LeetCode
  • Adobe
  • Amazon
  • Facebook
  • Microsoft
  • Hacker Earth
  • CSE Interview

Top Rated Questions

Given a float number convert it into the string WITHOUT using any inbuilt Function

Amazon Interview On-Campus For Internship – 1

The Magic HackerEarth Nirvana solutions Hiring Challenge

There are N nuts and N bolts, u have to find all the pairs of nuts and bolts in minimum no. of iteration

Stickler thief

Common Ancestor in a Binary Tree or Binary Search Tree

Flipkart Set 1 On Campus with Answers

Code Chef PRGIFT Solution

Maximum occurred Smallest integer in n ranges

K’th Largest Element in BST when modification to BST is not allowed

Inorder and Preorder traversals of a Binary Tree given. Output the Postorder traversal of it.

Naurki.com Security Breach

Print vertical sum of all the axis in the given binary tree

Printing intermediate Integers between one element & next element of array

Search element in a matrix with all rows and columns in sorted order

Convert number to words java

Serialise Deserialise N-ary Tree

VMWare Openings

Find min element in Sorted Rotated Array (Without Duplicates)

Number of Islands BFS/DFS

Practo Hiring Experience

Closed Parentheses checker

Rectangular chocolate bar Create at least one piece which consists of exactly nTiles tiles

Difference between a LinkedList and a Binary Search Tree BST

Find the kth number with prime factors 3, 5 and 7

Apriori algorithm C Code Data Mining

Facebook Interview Question : Interleave List

HackeEarth Flipkart’s Drone

Python String and numbers

Get Minimum element in O(1) from input numbers or Stack

Copyright © 2025 · Genesis Framework · WordPress · Log in