コード例 #1
0
ファイル: main.c プロジェクト: kyoken74/fizzbuzz
/**
 * 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;
}
コード例 #2
0
int main() {
    for(int i = 0; i <= 100; i++) {
        fizzbuzz(i);
    }
    
    return EXIT_SUCCESS;
}
コード例 #3
0
ファイル: fizz-buzz.cpp プロジェクト: sempuki/code
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;
}
コード例 #4
0
ファイル: c.c プロジェクト: Cuiying/FizzBuzz
int main(void)
{
    for (int i = 0; i <= 100; i++) {
        fizzbuzz(i);
    }

	return 0;
}
コード例 #5
0
ファイル: fizzbuzz.c プロジェクト: takeoverjp/kata
int
main (void)
{
  int i = 1;
  for (i = 1; i <= 100; i++)
    fizzbuzz (i);
  return 0;
}
コード例 #6
0
ファイル: fizzbuzz.c プロジェクト: jonlorusso/codeeval
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;
}
コード例 #7
0
ファイル: 0115_1.c プロジェクト: 12ashk/etude
int main(void)
{
	int i;
	printf("input number: ");
	scanf("%d", &i);
	fizzbuzz(i);
	printf("\n");

	return 0;
}
コード例 #8
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;
}
コード例 #9
0
ファイル: check_fizzbuzz.c プロジェクト: DNixonLLC/katas
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);
}
コード例 #10
0
ファイル: 001fizzbuzz.cpp プロジェクト: loadstar81/brainfood
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);
  }
}
コード例 #11
0
ファイル: main.c プロジェクト: m-wichmann/libConCoCt
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;
}
コード例 #12
0
ファイル: 0115_1.c プロジェクト: 12ashk/etude
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);
		}
	}
}
コード例 #13
0
TEST(fizzbuzz, shouldReturnBuzzFor5) {
	string actual = fizzbuzz(5);

    ASSERT_EQ("Buzz", actual);
}
コード例 #14
0
TEST(fizzbuzz, shouldReturn1For1) {
	string actual = fizzbuzz(1);

    ASSERT_EQ("1", actual);
}
コード例 #15
0
TEST(fizzbuzz, shouldReturnFizzbuzzFor15) {
	string actual = fizzbuzz(15);

    ASSERT_EQ("FizzBuzz", actual);
}
コード例 #16
0
ファイル: fizzbuzz.c プロジェクト: gdm9000/euler1
int
main (int argc, char **argv)
{
  cob_init (argc, argv);
  cob_stop_run (fizzbuzz ());
}
コード例 #17
0
ファイル: fizzbuzz.cpp プロジェクト: halcat0x15a/programming
int main() {
  for (int i = 1; i <= 100; i++)
    std::cout << fizzbuzz(i) << std::endl;
  return 0;
}