• 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

Longest Increasing Subsequence

Microsoft BING Interview Experience

Find the number ABCD such that when multipled by 4 gives DCBA.

Level order traversal in Spiral form

Given array of 0’s and 1’s. All 0’s are coming first followed by 1’s. find the position of first 1

In Given LinkedList Divide LL in N Sub parts and delete first K nodes of each part

Client Server C program

Given a string, find the first character which is non-repetitive

Printing Longest Common Subsequence

The Magic HackerEarth Nirvana solutions Hiring Challenge

Spanning Tree

simple sql injection

Walmart Labs Interview Experience

building with N steps, we can take 1,2,3 steps calculate number of ways to reach at top of building

write a c program that given a set a of n numbers and another number x determines whether or not there exist two elements in s whose sum is exactly x

Find the smallest window in a string containing all characters of another string

Find next greater number with same set of digits

Convert Decimal to Roman numbers / Romanizer HackerEarth Code

Find Nearest Minimum number in left side in O(n)

Coin Collection Dynamic Programming

Linked List V/S Binary Search Tree

Reversal of LinkedList

System Design: Designing a LLD for Hotel Booking

‘N’ Story Building, with 1,2,3 steps how many ways can a person reach top of building.

Maximum size of square sub matrix with all 1’s in a binary matrix

25 horses 5 tracks Find 3 fastest puzzle

Find the element that appears once others appears thrice

Cisco Hiring Event 21st – 22nd Feb 2015

BFS (Breath First Search)

Possible sizes of bus to carry n groups of friends

Copyright © 2026 · Genesis Framework · WordPress · Log in