#include <stdio.h>
int main() {
// 定数の定義
const double principal = 1000000.0; // 元本(円)
const double rate = 0.03; // 年利 3%
const double target = 1500000.0; // 目標金額(円)
// 変数の初期化
double amount = principal; // 元利合計
int years = 0; // 年数
// 複利計算ループ
while (amount <= target) {
amount *= (1 + rate); // 元利合計を更新
years++; // 年数を増加
}
// 結果の表示
printf("150万円を超える年数: %d年\n", years
); printf("そのときの元利合計: %.0f円\n", amount
);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbigpIHsKICAgIC8vIOWumuaVsOOBruWumue+qQogICAgY29uc3QgZG91YmxlIHByaW5jaXBhbCA9IDEwMDAwMDAuMDsgLy8g5YWD5pys77yI5YaG77yJCiAgICBjb25zdCBkb3VibGUgcmF0ZSA9IDAuMDM7ICAgICAgICAgICAvLyDlubTliKkgMyUKICAgIGNvbnN0IGRvdWJsZSB0YXJnZXQgPSAxNTAwMDAwLjA7ICAgIC8vIOebruaomemHkemhje+8iOWGhu+8iQoKICAgIC8vIOWkieaVsOOBruWIneacn+WMlgogICAgZG91YmxlIGFtb3VudCA9IHByaW5jaXBhbDsgLy8g5YWD5Yip5ZCI6KiICiAgICBpbnQgeWVhcnMgPSAwOyAgICAgICAgICAgICAvLyDlubTmlbAKCiAgICAvLyDopIfliKnoqIjnrpfjg6vjg7zjg5cKICAgIHdoaWxlIChhbW91bnQgPD0gdGFyZ2V0KSB7CiAgICAgICAgYW1vdW50ICo9ICgxICsgcmF0ZSk7IC8vIOWFg+WIqeWQiOioiOOCkuabtOaWsAogICAgICAgIHllYXJzKys7ICAgICAgICAgICAgICAvLyDlubTmlbDjgpLlopfliqAKICAgIH0KCiAgICAvLyDntZDmnpzjga7ooajnpLoKICAgIHByaW50ZigiMTUw5LiH5YaG44KS6LaF44GI44KL5bm05pWwOiAlZOW5tFxuIiwgeWVhcnMpOwogICAgcHJpbnRmKCLjgZ3jga7jgajjgY3jga7lhYPliKnlkIjoqIg6ICUuMGblhoZcbiIsIGFtb3VudCk7CgogICAgcmV0dXJuIDA7Cn0K