Created
June 1, 2017 01:28
-
-
Save sin-tanaka/af01bd794b95c722a5f56acc43a3d20b to your computer and use it in GitHub Desktop.
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
/* | |
iを1〜100まで出力する | |
* iが3の倍数 ==> 'Fizz' | |
* iが5の倍数 ==> 'Buzz' | |
* iが3と5の公倍数 ==> 'Fizz-Buzz' | |
* それ以外 ==> 数値をそのまま出力 | |
*/ | |
#include <stdio.h> | |
int main(void){ | |
int i; | |
for (i = 1; i <= 100; i++) { | |
if (i % 3 == 0 && i % 5 == 0) /* iが3の倍数かつ5の倍数 */ | |
printf("Fizz-Buzz\n"); | |
else if (i % 3 == 0) /* iが3の倍数(かつ5の倍数でない) */ | |
printf("Fizz\n"); | |
else if (i % 5 == 0) /* iが5の倍数(かつ3の倍数でない) */ | |
printf("Buzz\n"); | |
else /* iが3の倍数でも5の倍数でもない */ | |
printf("%d\n", i); | |
} | |
return 0; | |
} |
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
""" | |
iを1〜100まで出力する | |
* iが3の倍数 ==> 'Fizz' | |
* iが5の倍数 ==> 'Buzz' | |
* iが3と5の公倍数 ==> 'Fizz-Buzz' | |
* それ以外 ==> 数値をそのまま出力 | |
""" | |
if __name__=='__main__': | |
for i in range(1, 101): | |
if i % 3 == 0 and i % 5 == 0: # iが3の倍数かつ5の倍数 | |
print("Fizz-Buzz") | |
elif i % 3 == 0: # iが3の倍数(かつ5の倍数でない) | |
print("Fizz") | |
elif i % 5: # iが5の倍数(かつ3の倍数でない) | |
print("Buzz") | |
else: # iが3の倍数でも5の倍数でもない | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment