Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C FizzBuzz!

Name: Anonymous 2013-02-27 23:35


/******************************************************************************
 * FizzBuzz
 *
 * Purpose:
 *      Program for testing division by 3, 5, or 15 and printing the message
 *      "Fizz", "Buzz", or "FizzBuzz", respectively.  If no factoring, prints
 *      the number.
 *
 * Usage:
 *      FizzBuzz [options]
 *
 * Options:
 *      -l<number>      specifies the starting number(default 1);
 *      -h<number>      specifies the final number (default 100);
 *      -f<text>        division by 3 text (default "Fizz");
 *      -b<text>        division by 5 text (default "Buzz");
 *      -v              verbose.  prints out numbers of fizz, buzz and fizzbuzz
 ****************************************************************************/

#include <stdio.h>
#include <stdlib.h>

int verbose = 0;                //verbose counter set to false(0)
int low = 1;                    //minimum number.  default 1
int high = 100;                 //maximum number. default 100
char *Fizz = "Fizz";            //Fizz string.  Set to "Fizz!"                
char *Buzz = "Buzz";            //Buzz string. Set to "Buzz!"
int i;                          //counter for cycling through sequence


int fizz_count = 0;             //counter for Fizz
int buzz_count = 0;             //counter for Buzz
int fizzbuzz_count = 0;         //counter for FizzBuzz

char *program_name;             //name of program (for error messages)

/****************************************************************************
 * FizzBuzz -- the actual FizzBuzz function that checks for divsions.
 *
 * Also, increments the counters for the FinalCount function.
 *
 * Parameters
 *      num -- the number to be checked for division
 ***************************************************************************/

void FizzBuzz(int num)
{
        if(num % 15 == 0)               //check for 15 factor
        {
                printf("%s%s\n", Fizz, Buzz);
                fizzbuzz_count++;
        }
        else if(num % 3 == 0)           //check for 3 factor
        {
                printf("%s\n", Fizz);
                fizz_count++;
        }
        else if(num % 5 == 0)           //check for 5 factor
        {
                printf("%s\n", Buzz);
                buzz_count++;
        }
        else                            //print number in other cases
                printf("%i\n", num);
}

1/2

Name: Anonymous 2013-02-27 23:43

my suspicions about /prog/ have been confirmed

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List