Skip to content

Instantly share code, notes, and snippets.

@Terminus-IMRC
Last active August 29, 2015 14:13
Show Gist options
  • Save Terminus-IMRC/699c052c90ef56eef767 to your computer and use it in GitHub Desktop.
Save Terminus-IMRC/699c052c90ef56eef767 to your computer and use it in GitHub Desktop.
とある人のソースの誤りの指摘と解説
とある人のソースの誤りの指摘と解説
#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