Answer to Question #280131 in C for rod

Question #280131

Let’s play a game of FizzBuzz! It’s quite the same with your childhood "PopCorn" game, but with a little bit of twist to align it with programming.




Are you ready?




Instructions:


Input a positive integer in one line. This will serve as the ending point of your loop.

Loop from 1 to the ending point (inclusive) and perform the following statements:

If the number is only divisible by 3, print "Fizz"

If the number is only divisible by 5, print "Buzz"

If the number is divisible by both 3 and 5, print "FizzBuzz"

If nothing is true in the previous conditions, skip the number


1
Expert's answer
2021-12-15T16:23:00-0500
#include <stdio.h>
#include <string.h>
#include <ctype.h>


int main(){
	int positiveInteger;
	//Input a positive integer in one line. This will serve as the ending point of your loop.
	printf("Enter positive integer: ");
	scanf("%d",&positiveInteger);
	//Loop from 1 to the ending point (inclusive) and perform the following statements:
	for(int i=1;i<=positiveInteger;i++){
		//If the number is only divisible by 3, print "Fizz"
		if(i%3==0){
			printf("Fizz\n");
		}
		//If the number is only divisible by 5, print "Buzz"
		if(i%5==0){
			printf("Buzz\n");
		}
		//If the number is divisible by both 3 and 5, print "FizzBuzz"
		if(i%3==0 && i%5==0){
			printf("FizzBuzz\n");
		}
		//If nothing is true in the previous conditions, skip the number
	}




	getchar();
	getchar();
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS