|
发表于 2020-2-21 16:43:56
|
显示全部楼层
本帖最后由 逆の夜 于 2020-2-21 17:37 编辑
测试题:
0.10个
1.不打印
2.c b a
3.14 5 9
4.z=x>0?x:-x;
5.
A.- if(size>12)
- {
- cost *= 1.05;
- flag = 2;
- }
- bill = cost*flag;
复制代码
B.- if(ibex>14)
- {
- sheds=3;
- }
- sheds=2;
- help=2*sheds;
复制代码
C.- scanf("%d",&score);
- if(score<0)
- {
- printf("cont=%d\n",count);
- }
- count++;
复制代码
动动手:
0.- #include <stdio.h>
- #include<math.h>
- #define yu 10000.0
- #define ye 10000.0
- int main()
- {
- double ye_sum,yu_sum;
- double lonely_rates=0.1,complex_rates=0.05;
- int year=0;
- while(++year)
- {
- yu_sum=yu+yu*lonely_rates*year;
- ye_sum=ye*pow(1+complex_rates,year);
- if(ye_sum>yu_sum)
- {
- printf("%d年后,黑夜的投资额超过小甲鱼!\n",year);
- printf("小甲鱼的投资额是:%.2lf\n",yu_sum);
- printf("黑夜的投资额是:%.2lf\n",ye_sum);
- break;
- }
- }
- }
复制代码
1.- #include <stdio.h>
- #include<math.h>
- #define Expend 500000.0
- int main()
- {
- int year=0;
- double sum=4000000;
- while(++year)
- {
- sum=sum-Expend;
- if(sum<0)
- {
- printf("%d年之后,小甲鱼败光了所有的家产,再次回到一贫如洗......\n",year);
- break;
- }
- sum=sum*(1+0.08);
- }
- }
复制代码
2.- #include <stdio.h>
- #include<math.h>
- int main()
- {
- double pi_4=1,pi,temple;
- int count=0;
- while(++count)
- {
- temple=pow(-1,count)/(1+2*count);
- pi_4=pi_4+temple;
- if(fabs(temple)>=pow(10,-9)&&fabs(temple)<pow(10,-8))
- {
- break;
- }
- }
- pi=4*pi_4;
- printf("π≈%.7lf",pi);
- }
复制代码
3.- #include <stdio.h>
- int main()
- {
- int month;
- long int rabbits=0;
- long int count=1,count2=0;
- long int total_rabbits;
- for(month=1;month<4;month++)
- {
- rabbits=rabbits+count;
- if(month==2)
- {
- count2=rabbits;
- }
- }
- for(month=4;month<24;month++)
- {
- total_rabbits=rabbits+count2;
- count2=rabbits;
- rabbits=total_rabbits;
- }
- printf("两年后可以繁殖%ld对兔子\n",total_rabbits);
- }
复制代码 |
|