0.#include<stdio.h>
int main()
{
double fish=10000, night=10000, temp = fish*0.1;
int count=0;
while (fish >= night)
{
fish += temp;
night += night*0.05;
count++;
}
printf("After %d years, night has more money than fish\n", count);
printf("Fish:%.2f\n", fish);
printf("Night:%.2f\n", night);
return 0;
}
1.#include<stdio.h>
int main()
{
double ivm=400;
int count=0;
while (ivm>0)
{
ivm -= 50;
ivm += ivm*0.08;
count++;
}
printf("After %d years fish used all his money.\n", count);
return 0;
}
2.#include<stdio.h>
#include<math.h>
int main()
{
double pi=0, temp=1;
while (fabs(1/temp) >= pow(10, -8))
{
pi += 1/temp;
pi = -pi;
temp += 2;
}
printf("Result: %.7f\n", 4.0*fabs(pi));
return 0;
}
3.#include<stdio.h>
int main()
{
int a=0, b=1, c;
for (int i=1; i<=24; i++)
{
c = a + b;
a = b;
b = c;
}
printf("The total number of rabbits: %d\n", b);
return 0;
}
|