Exemple #1
0
/**
 * Provides CLI for FizzBuzz algorithm.
 *
 * Usage:
 *      fizzbuzz [ max ]
 */
int main(int argc, char** argv) {

    int max = DEFAULT_MAX;
    size_t bufsiz = fizzbuzz_bufsiz(max);
    char* buf = malloc(bufsiz); /* allocate the buffer for max width */

    if (argc > 1) {
        max = atoi(argv[1]);
    }

    /* For each integer from 0 to the max, evaluate fizzbuzz algorithm */
    {
        int i = 0;
        for ( ; i <= max; i++) {
            fizzbuzz(buf, bufsiz, i);
            puts(buf);
            /*
                We chose not to use the mfizzbuzz, because mfizzbuzz allocates
                heap memory every time we call it, which means we must free it
                when we are done. In this implementation, as soon as we call
                the function, we print it to stdout. We have no need to retain
                the results from multiple fizzbuzz calls. It is therefore more
                efficient to allocate memory once, and reuse it.

            char* buf = mfizzbuzz(i);
            puts(buf);
            free(buf);
            */
        }
    }

    free(buf); /* free the buffer */

    return 0;
}
int main() {
    for(int i = 0; i <= 100; i++) {
        fizzbuzz(i);
    }
    
    return EXIT_SUCCESS;
}
Exemple #3
0
int main (int argc, char **argv)
{
    if (argc != 2)
    {
        std::cout << "input must be a valid filename" << std::endl;
        return -1;
    }

    std::ifstream file (argv[1]);
    std::string line, a, b, n;

    if (!file)
    {
        std::cout << "input must be a file" << std::endl;
        return -2;
    }

    while (std::getline (file, line).eof() == false)
    {
        std::stringstream buffer (line);
        buffer >> a >> b >> n;
        fizzbuzz (std::atoi (a.c_str()), 
                  std::atoi (b.c_str()), 
                  std::atoi (n.c_str()));
    }

    return 0;
}
Exemple #4
0
int main(void)
{
    for (int i = 0; i <= 100; i++) {
        fizzbuzz(i);
    }

	return 0;
}
Exemple #5
0
int
main (void)
{
  int i = 1;
  for (i = 1; i <= 100; i++)
    fizzbuzz (i);
  return 0;
}
Exemple #6
0
int main(int argc, char *argv[])
{
    FILE *file = fopen(argv[1], "r");

    int a, b, n;
    while (fscanf(file, "%d %d %d", &a, &b, &n) != EOF)
        fizzbuzz(a, b, n);

    return 0;
}
Exemple #7
0
int main(void)
{
	int i;
	printf("input number: ");
	scanf("%d", &i);
	fizzbuzz(i);
	printf("\n");

	return 0;
}
int main() {
    int T;
    int N;
    scanf("%d", &T);
    
    for (int i = 0; i < T; i++) {
        scanf("%d", &N);
        printf("%ld\n", fizzbuzz(N)); 
    }
    return 0;
}
Exemple #9
0
END_TEST

START_TEST(fizzbuzz_should_return_EXIT_FAILURE_when_the_results_buffer_is_too_small_to_hold_the_conversion) {
  int numberToFizzBuzz = 0;
  size_t sizeOfResultsBuffer = 1;
  char resultsBuffer[1];
  int fizzbuzzStatus = EXIT_SUCCESS;

  fizzbuzzStatus = fizzbuzz(numberToFizzBuzz, resultsBuffer, &sizeOfResultsBuffer);

  ck_assert(fizzbuzzStatus == EXIT_FAILURE);
}
Exemple #10
0
void readTestsFromFile(const char* filePath) {
  assert(filePath);
  std::string lineBuffer;
  std::ifstream file;
  file.open(filePath);
  while (std::getline(file, lineBuffer)) {
    if (lineBuffer.empty()) { continue; }
    std::stringstream stream(lineBuffer);
    int A, B, N;
    stream >> A >> B >> N;
    fizzbuzz(A, B, N);
  }
}
Exemple #11
0
int main()
{
    int number = 1;
    char string[10];
    
    while(number != 0) {
        printf("Enter number (0 to exit): ");
        scanf("%d", &number);
        fizzbuzz(number, string);
        printf("%s\n", string);
    }

    return 0;
}
Exemple #12
0
void fizzbuzz(int i)
{
	if(i == 1){
		printf(" %d", i);
	}
	else{
		if(i % 3 == 0 && i % 5 == 0){
			fizzbuzz(i-1);
			printf(" FizzBuzz\n");
		}
		else if(i % 3 == 0){
			fizzbuzz(i-1);
			printf(" Fizz");
		}
		else if(i % 5 == 0){
			fizzbuzz(i-1);
			printf(" Buzz");
		}
		else{
			fizzbuzz(i-1);
			printf(" %d", i);
		}
	}
}
TEST(fizzbuzz, shouldReturnBuzzFor5) {
	string actual = fizzbuzz(5);

    ASSERT_EQ("Buzz", actual);
}
TEST(fizzbuzz, shouldReturn1For1) {
	string actual = fizzbuzz(1);

    ASSERT_EQ("1", actual);
}
TEST(fizzbuzz, shouldReturnFizzbuzzFor15) {
	string actual = fizzbuzz(15);

    ASSERT_EQ("FizzBuzz", actual);
}
Exemple #16
0
int
main (int argc, char **argv)
{
  cob_init (argc, argv);
  cob_stop_run (fizzbuzz ());
}
Exemple #17
0
int main() {
  for (int i = 1; i <= 100; i++)
    std::cout << fizzbuzz(i) << std::endl;
  return 0;
}