fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int day = 1;
  5. int saving = 1; // 当日貯金する額(1円から始まって毎日2倍)
  6. int total = 1; // 貯金の合計(初日は1円)
  7.  
  8. printf("%d日目までの合計金額\t%d円\n", day, total);
  9.  
  10. while (total <= 10000) {
  11. saving *= 2; // 翌日の貯金額(2倍)
  12. day++;
  13. total += saving; // 合計額を更新
  14.  
  15. printf("%d日目までの合計金額\t%d円\n", day, total);
  16. }
  17.  
  18. printf("\n1万円を超えたのは%d日目、合計金額は%d円でした。\n", day, total);
  19.  
  20. return 0;
  21. }
  22.  
  23.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
1日目までの合計金額	1円
2日目までの合計金額	3円
3日目までの合計金額	7円
4日目までの合計金額	15円
5日目までの合計金額	31円
6日目までの合計金額	63円
7日目までの合計金額	127円
8日目までの合計金額	255円
9日目までの合計金額	511円
10日目までの合計金額	1023円
11日目までの合計金額	2047円
12日目までの合計金額	4095円
13日目までの合計金額	8191円
14日目までの合計金額	16383円

1万円を超えたのは14日目、合計金額は16383円でした。