Question

Write a C program that prints the numbers from 1 to 100, but substitutes the word...

Write a C program that prints the numbers from 1 to 100, but substitutes the word “fizz” if the number is evenly divisble by 3, and “buzz” if the number is divisible by 5, and if divisible by both prints “fizz buzz” like this: 1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 fizz buzz 16 17 fizz 19 buzz ... and so on

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

int main()
{
int i;
  
for(i=1; i<=100; i++){
if( i % 5 == 0 && i % 3 == 0){
printf("fizz buzz\n");
}
else if( i % 3 == 0){
printf("fizz\n");
} else if( i % 5 == 0){
printf("buzz\n");
} else{
printf("%d\n", i);
}
}

return 0;
}

Output:

sh-4.2$ gcc -o main *.c   
sh-4.2$ main
1   
2   
fizz
4   
buzz
fizz

7   
8   
fizz
buzz
11
fizz
13
14
fizz buzz   
16
17
fizz
19
buzz
fizz
22
23
fizz

so on

Add a comment
Know the answer?
Add Answer to:
Write a C program that prints the numbers from 1 to 100, but substitutes the word...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program that prints the numbers from 1 to 100. But for multiples of...

    Write a C 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”.

  • Write a program that prints the numbers from 1 to 100. But for multiples of three...

    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”. Hints: You can use a for loop with a range to simplify the iteration Use the modulo division operator (%) to find the remainder of a division calculation

  • LANGUAGE C++ I need help with all 3 questions. Thank you in advance Password Generator← 10...

    LANGUAGE C++ I need help with all 3 questions. Thank you in advance Password Generator← 10 10.201.51. eRAD D scheduling山UitPro 6 Fizz Buzz Write a function "void FizzBuzz(int n)" that lists all of the numbers from 1 to n, but replace all numbers divisible by 3 but not divizible by 5 with the word "Fizz", replace all numbers divisible by 5 but not divisible by 3 with the word "Buzz", and replace all numbers divisible by both 3 and 5...

  • 8.(a) Write a program that prints all of the numbers from 0 to 102 divisible by...

    8.(a) Write a program that prints all of the numbers from 0 to 102 divisible by either 3 or 7. ​ (b) Write a program that prints all of the numbers from 0 to 102 divisible by both 3 and 7 (c) Write a program that prints all of the even numbers from 0 to 102 divisible by both 3 and 7 (d) Write a program that prints all of the odd numbers from 0 to 102 divisible by both...

  • Python: Using your favorite text editor, write a program that outputs the string representation of numbers...

    Python: Using your favorite text editor, write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”. Submit by uploading a .py file Example: n = 15, Return: [ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"...

  • Python Create a function for the Fizz Buzz program (see Assignment01, Q11). The function takes the...

    Python Create a function for the Fizz Buzz program (see Assignment01, Q11). The function takes the following 3 arguments with default values: 1) max_iteration=100 2) fizz_divider=3 3) buzz_divider=5 The function iterates numbers from 1 to max_iteration any number divisible by fizz_divider, “print fizz” Any number divisible by buzz_divider, “print buzz” Any number divisible by fizz_divider and buzz_divider, print “fizz buzz” Otherwise, print the number

  • Use Python3 Write a program that prints the numbers from 1 up to 105 (inclusive), one...

    Use Python3 Write a program that prints the numbers from 1 up to 105 (inclusive), one per line. However, there are three special cases where instead of printing the number, you print a message instead: 1. If the number you would print is divisible by 3, print the message: The dog of wisdom knows all about this number. 2. If the number you would print is divisible by 7, print the message: Hold on I have a meme for this....

  • Write a program that prints all the 3 digit numbers that are divisible by 17

    Write a program that prints all the 3 digit numbers that are divisible by 17

  • Write a C program that takes a positive integer n as input and prints all the...

    Write a C program that takes a positive integer n as input and prints all the prime numbers from 1 to n. Sample Input/Output 1: Enter your n: 20 Prime number(s) from 1 to 20 : 2 3 5 7 11 13 17 19 Sample Input/Output 2: Enter your n:2Prime number(s) from 1 to 2 : 2

  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:             0 Sunday                     1 Monday                   2 Tuesday                   3 Wednesday       4 Thursday                 5 Friday                      6 Saturday Your program should...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT