|
发表于 2020-12-9 15:47:48
|
显示全部楼层
0.
- # include <stdio.h>
- # include <math.h>
- # define money 10000
- int main ()
- {
- double fish_money = money, night_money = money;
- double rate1 = 0.1, rate2 = 0.05;
- int year = 1;
-
- do
- {
- fish_money = money * rate1 * year + money;
- night_money = money * pow((1 + rate2), year);
- year++;
- continue;
- }
- while(fish_money > night_money);
-
- printf("%d年后,黑夜的投资额超过小甲鱼!\n", year - 1);
- printf("小甲鱼的投资额是:%.2lf\n", fish_money);
- printf("黑夜的投资额是:%.2lf\n", night_money);
-
-
- return 0;
- }
复制代码
1.
- # include <stdio.h>
- int main ()
- {
- int year = 0;
- double money = 4000000;
- double rate = 0.08;
-
- while (money >= 0)
- {
- money = money - 500000;
- money = money * (1 + rate);
- year++;
- }
- printf("%d年之后,小甲鱼败光了所有的家产,再次回到一贫如洗......\n", year);
-
- return 0;
- }
复制代码
2.
- # include <stdio.h>
- # include <math.h>
- int main ()
- {
- double num = 1, pi = 0;
- int i = -1;
-
- while (fabs(i / num) > 1e-8)
- {
- i = -i;
- pi = i / num + pi;
- num += 2;
- }
-
- pi = pi * 4;
- printf("pi = %.7f", pi);
-
- return 0;
- }
复制代码
3.
- # include <stdio.h>
- int main ()
- {
- int month;
- int f1 = 1, f2 = 1, f3;
-
- for (month = 1; month <= 24; month++)
- {
- f3 = f1 + f2;
- f1 = f2;
- f2 = f3;
- }
- printf("%d", f3);
-
- return 0;
- }
复制代码 |
|