Title description
The FizzBuzz game requires players to replace specific numbers when reporting the number. Please write a program, the input is a positive integer n, n<=100. Print the integers from 1 to n in turn, if the number is divisible by 3, print Fizz; if it is divisible by 5, print Buzz; if it can Print FizzBuzz when it is divisible by 3 and 5; otherwise, print the number. There is a space between the two prints.
Input and output format
Input format
A positive integer n
Output format
One line of string
Sample input and output
Input example 1
1
Sample output 1
1
Input example 2
5
Sample output 2
1 2 Fizz 4 Buzz
Input sample 3
16
Sample output 3
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16
answer
Water question~
Direct for+(if else) enumeration judgment, easy AC this question
Code
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
if(i%15==0) printf("FizzBuzz ");
else if(i%3==0) printf("Fizz ");
else if(i%5==0) printf("Buzz ");
else printf("%d ",i);
}
return 0;
}