#include <stdio.h>
#include <math.h>
int main() {
// 初期設定
double principal = 1000000; // 元金 100万円
double rate1 = 0.02; // 年利2%
double rate2 = 0.03; // 年利3%
int years = 10; // 運用期間(年利2%)
double target = 1500000; // 目標金額 150万円
// 年利2%での計算
double totalAmount
= principal
* pow(1 + rate1
, years
); printf("年利2%%で10年間複利運用した場合の元利合計: %.2f円\n", totalAmount
);
// 年利3%で目標金額を超えるまでの年数を計算
int yearCount = 0;
double amount = principal;
while (amount <= target) {
amount *= (1 + rate2);
yearCount++;
}
printf("年利3%%で元利合計が150万円を超えるまでの年数: %d年\n", yearCount
);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CgppbnQgbWFpbigpIHsKICAgIC8vIOWIneacn+ioreWumgogICAgZG91YmxlIHByaW5jaXBhbCA9IDEwMDAwMDA7IC8vIOWFg+mHkSAxMDDkuIflhoYKICAgIGRvdWJsZSByYXRlMSA9IDAuMDI7ICAgICAgICAvLyDlubTliKkyJQogICAgZG91YmxlIHJhdGUyID0gMC4wMzsgICAgICAgIC8vIOW5tOWIqTMlCiAgICBpbnQgeWVhcnMgPSAxMDsgICAgICAgICAgICAgLy8g6YGL55So5pyf6ZaT77yI5bm05YipMiXvvIkKICAgIGRvdWJsZSB0YXJnZXQgPSAxNTAwMDAwOyAgICAvLyDnm67mqJnph5HpoY0gMTUw5LiH5YaGCgogICAgLy8g5bm05YipMiXjgafjga7oqIjnrpcKICAgIGRvdWJsZSB0b3RhbEFtb3VudCA9IHByaW5jaXBhbCAqIHBvdygxICsgcmF0ZTEsIHllYXJzKTsKICAgIHByaW50Zigi5bm05YipMiUl44GnMTDlubTplpPopIfliKnpgYvnlKjjgZfjgZ/loLTlkIjjga7lhYPliKnlkIjoqIg6ICUuMmblhoZcbiIsIHRvdGFsQW1vdW50KTsKCiAgICAvLyDlubTliKkzJeOBp+ebruaomemHkemhjeOCkui2heOBiOOCi+OBvuOBp+OBruW5tOaVsOOCkuioiOeulwogICAgaW50IHllYXJDb3VudCA9IDA7CiAgICBkb3VibGUgYW1vdW50ID0gcHJpbmNpcGFsOwogICAgd2hpbGUgKGFtb3VudCA8PSB0YXJnZXQpIHsKICAgICAgICBhbW91bnQgKj0gKDEgKyByYXRlMik7CiAgICAgICAgeWVhckNvdW50Kys7CiAgICB9CiAgICBwcmludGYoIuW5tOWIqTMlJeOBp+WFg+WIqeWQiOioiOOBjDE1MOS4h+WGhuOCkui2heOBiOOCi+OBvuOBp+OBruW5tOaVsDogJWTlubRcbiIsIHllYXJDb3VudCk7CgogICAgcmV0dXJuIDA7Cn0K