-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFizzBuzz.c
More file actions
30 lines (30 loc) · 714 Bytes
/
FizzBuzz.c
File metadata and controls
30 lines (30 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
char ** fizzBuzz(int n, int* returnSize)
{
*returnSize = n;
char** answer;
answer = malloc(n * sizeof(char*));
for (int i = 1; i < n + 1; i++)
{
char* s;
if (i % 15 == 0)
{
answer[i - 1] = strdup("FizzBuzz");
}
else if (i % 5 == 0)
{
answer[i - 1] = strdup("Buzz");
}
else if (i % 3 == 0)
{
answer[i - 1] = strdup("Fizz");
}
else
{
int length = snprintf(NULL, 0, "%d", i);
char* i_str = malloc(length + 1);
snprintf(i_str, length + 1, "%d", i);
answer[i - 1] = i_str;
}
}
return answer;
}