#include <stdio.h>
int main() {
float money_xjy = 10000;
float money_hy = 10000;
int year = 0;
while (money_xjy >= money_hy) {
year++;
money_xjy += 10000*0.1;
money_hy *= 1.05;
}
printf("%d年后,黑夜的投资额超过小甲鱼!\n\
小甲鱼的投资额是:%.2f 元\n\
黑夜的投资额是:%.2f 元\n\
", year, money_xjy, money_hy);
return 0;
}
#include <stdio.h>
#define PRICE 4000000
#define OVERHEAD 500000
int main() {
int year = 0;
double fortune = PRICE;
do {
fortune -= OVERHEAD;
year++;
fortune *= 1.08;
} while (fortune > 0);
printf("%d年后,小甲鱼败了家产,再次回到一贫如洗...\n", year);
return 0;
}
#include <stdio.h>
#include <math.h>
int main() {
int i = 0;
double num = 1;
double den = 1;
double pi = 0;
while (num/den > pow(10, -8)) {
pi += pow(-1, i)*(num/den);
i++;
den += 2;
}
pi = pi*4;
printf("Pi = %.7f\n", pi);
return 0;
}
#include <stdio.h>
int main() {
long a=1, b=1, c, i;
for (i=3; i<=24; i++) {
c = a+b;
a = b;
b = c;
}
printf("2年后,总共有%ld只兔子!\n");
return 0;
}
|