-
Notifications
You must be signed in to change notification settings - Fork 68
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
413e89a
commit eadb00d
Showing
1 changed file
with
46 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
char *itoa(int num, char buffer[]); | ||
int contiene(int num, int numero); | ||
|
||
int main(void) { | ||
int i; | ||
|
||
for(i = 1; i <= 100; i++) { | ||
if((i % 3 == 0 || contiene(i, 3) == 1) && (i % 5 == 0 || contiene(i, 5) == 1)) { | ||
printf("FizzBuzz\n"); | ||
} else if((i % 3 == 0 || contiene(i, 3) == 1) && (i % 5 != 0)) { | ||
printf("Fizz\n"); | ||
} else if((i % 3 != 0) && (i % 5 == 0 || contiene(i, 5) == 1)) { | ||
printf("Buzz\n"); | ||
} else { | ||
printf("%d\n", i); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
char *itoa(int num, char buffer[]) { | ||
sprintf(buffer, "%d", num); | ||
|
||
return buffer; | ||
} | ||
|
||
// chequea si un string contiene o no un num | ||
// si lo contiene devuelve 1 sino devuelve -1 | ||
int contiene(int num, int numero) { | ||
char buffer[4]; | ||
itoa(num, buffer); | ||
int result =-1; | ||
int i; | ||
for(i = 0; i < strlen(buffer); i++) { | ||
if((buffer[i] - '0') == numero) { | ||
result = 1; | ||
break; | ||
} | ||
} | ||
return result; | ||
} |