Last active
August 29, 2015 14:13
-
-
Save Terminus-IMRC/699c052c90ef56eef767 to your computer and use it in GitHub Desktop.
とある人のソースの誤りの指摘と解説
This file contains hidden or 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 hidden or 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
#include <stdio.h> | |
int main(void) | |
{ | |
double money = 1000.0; | |
int month = 0; | |
while (money < 1000000.0) { | |
money = money * 1.001 + 1000.0; | |
month ++; | |
/* | |
* %8.0f - 後指定のdouble型の変数を、整数部右詰め8桁、小数部なしで印字 | |
* \n - 改行を印字 (全角文字の\ではなく半角文字の\を用いることに注意) | |
*/ | |
printf("%2dか月後: %8.0f円\n", month, money); | |
} | |
/* | |
* \n - 同上 | |
* month % 12 - 変数monthを12で除算した剰余を表す (元ソースのmonth%d12はtypoであると思われる) | |
*/ | |
printf("%d年%dか月で100万円達成できました\n", month / 12, month % 12); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment