-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62fdd34
commit 332cdbb
Showing
7 changed files
with
172 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <limits.h> | ||
#include <stdbool.h> | ||
#include <stddef.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
static bool terms(size_t const n) { | ||
if (printf("(1") < 0) | ||
return false; | ||
|
||
for (size_t i = 0; i < n; ++i) | ||
if (printf(" * %zu", i + 1) < 0) | ||
return false; | ||
|
||
if (printf(")") < 0) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
static bool dirs(size_t const n) { | ||
for (size_t i = 0; i <= n; ++i) | ||
if (printf("#define BMM_FACT_%zu() ", i) < 0 || | ||
!terms(i) || | ||
printf("\n") < 0) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
int main(int const argc, char** const argv) { | ||
if (argc != 2) | ||
return EXIT_FAILURE; | ||
|
||
unsigned long int n = strtoul(argv[1], NULL, 10); | ||
if (n == ULONG_MAX) | ||
return EXIT_FAILURE; | ||
|
||
if (!dirs((size_t) n)) | ||
return EXIT_FAILURE; | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters