-2
void fizzBuzz(int n) {

for (int i = 0; i < n; i++){
    if (i % 3 == 0 && i % 5 == 0){
        printf("FizzBuzz\n");}
    else if (i % 3 == 0 && i % 5 != 0){
        printf("Fizz\n");}
    else if (i % 3 != 0 && i % 5 == 0){
        printf("Buzz\n");}
    else
    printf("%d", i);}
}

int main() {

int n;
scanf("%d", &n);

print_all(n);
return 0;
}

I want to use the fizzbuzz function in my main function. how do I call void Fizzbuzz(int n) function and have it accept user input as shown?

1 Answers1

0

How to

Just call it by its name and pass the parameters needed. like this:

fizzBuzz(6);

Here you are calling the function fizzBuzz and passing it a parameter of type integer which value is 6. If you want to do it with variables is the same way, just pass the variable (of type integer) as the parameter of the function. Like this:

int n = 6;
fizzBuzz(n);

You would obtain the same output.

Inside your main function would be:

int main() {

int n; //variable of type integer
scanf("%d", &n); //value of n given by user input
fizzBuzz(n); //the function call here
print_all(n);
return 0;
}
3rickDJ
  • 1
  • 2