# 实验三

2020-12-06 14:40:45

#第一题

``````
/*
* @Author: 曾钰芝
* @Date: 2020-12-06 14:01:12
* @LastEditTime: 2020-12-06 14:01:12
* @Description: In User Settings Edit
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\实验三1.c
*/
int main()
{
char ch ='\0';
printf("input a char:\n");
scanf("%c",&ch);
if(ch>='a'&&ch<='z')
ch = ch-32;
printf("%c\n",ch);

return 0;
}

``````

#第二题

``````
/*
* @Author: 曾钰芝
* @Date: 2020-12-06 14:01:12
* @LastEditTime: 2020-12-06 14:01:12
* @Description: In User Settings Edit
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\实验三2.c
*/
int main() {
int x,y;
printf("请输入x的值:");
scanf("%d",&y);
if (x<=8 && x>=0)
y=x+2*x*x+10
if (x<0 || x>8)
y=x-3*x*x*x-9

printf("y的值为%d",y);

return 0;
}

``````

#第三题

``````
/*
* @Author: 曾钰芝
* @Date: 2020-12-06 14:01:12
* @LastEditTime: 2020-12-06 14:01:12
* @Description: In User Settings Edit
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\实验三3.c
*/
int main() {
int score;
printf("请输入学生的成绩:");
scanf("%d",&score);

if(score>=90)
printf("该学生的等级为:优秀",score);
else if(score>=80)
printf("该学生的等级为:良好",score);
else if(score>=70)
printf("该学生的等级为:中等",score);
else if(score>=60)
printf("该学生的等级为:及格",score);
else if(score<60)
printf("该学生的等级为:不及格",score);

return 0;
}

``````

#第四题

``````
/*
* @Author: 曾钰芝
* @Date: 2020-12-06 14:01:12
* @LastEditTime: 2020-12-06 14:01:12
* @Description: In User Settings Edit
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\实验三4.c
*/
#include<math.h>
#include<stdlib.h>

int main() {
float x,y;
printf("请输入x:");
scanf("%f",&x);
if (x<=-1){
printf("x不满足条件");
}
else{
y=(sin(x))+log(x+1)/(exp(x))+abs(cos(x));
}
printf("y=",y);
return 0;
}

``````

#第五题

``````
/*
* @Author: 曾钰芝
* @Date: 2020-12-06 14:01:12
* @LastEditTime: 2020-12-06 14:01:12
* @Description: In User Settings Edit
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\实验三5.c
*/
int main() {
long long i=0,num;
printf("Enter a number:");
scanf("%lld",&num);

while(num!=0){
num=num/10;
i++;
}
printf("The number has %lld digits\n",i);

return 0;

}

``````

#第六题

``````
/*
* @Author: 曾钰芝
* @Date: 2020-12-06 14:01:12
* @LastEditTime: 2020-12-06 14:01:12
* @Description: In User Settings Edit
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\实验三6.c
*/
int main() {
int time;
printf("Enter a 24-hour time:");
scanf("%d",&time);

if(time>12.00)
printf("Equivalent 12-hour time:%dPM",time);
else if(time<=12.00)
printf("Equivalent 12-hour time:%dAM",time);

return 0;
}

``````

#第七题

``````
/*
* @Author: 曾钰芝
* @Date: 2020-12-06 14:01:12
* @LastEditTime: 2020-12-06 14:01:12
* @Description: In User Settings Edit
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\实验三7.c
*/
int main() {
float value,commission;
scanf("%f",&value);
if (value<2500)
commission=30+value*0.017;
else if (value<6250)
commission=56+value*0.0066;
else if (value<20000)
commission=76+value*0.0034;
else if (value<50000)
commission=100+value*0.0022;
else if (value<500000)
commission=155+value*0.0011;
else if (value>500000)
commission=255+value*0.009;

printf("Commission:\$%.2f",commission);

return 0;
}

``````

#第八题

``````
/*
* @Author: 曾钰芝
* @Date: 2020-12-06 14:01:12
* @LastEditTime: 2020-12-06 14:01:12
* @Description: In User Settings Edit
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\实验三8.c
*/
int main() {
float speed;
printf("请输入风速(海里/小时)");
scanf("%f",&speed);
if (speed<1)
printf("%f(海里/小时)的风速等级是无风");
else if (speed<=3)
printf("%f(海里/小时)的风速等级是轻风");
else if (speed<=27)
printf("%f(海里/小时)的风速等级是微风");
else if (speed<=47)
printf("%f(海里/小时)的风速等级是大风");
else if (speed<=63)
printf("%f(海里/小时)的风速等级是暴风");
else if (speed>63)
printf("%f(海里/小时)的风速等级是飓风");

return 0;
}

``````

#第九题

``````
/*
* @Author: 曾钰芝
* @Date: 2020-12-06 14:01:12
* @LastEditTime: 2020-12-06 14:01:12
* @Description: In User Settings Edit
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\实验三9.c
*/
int main() {
float salary,tax;
printf("请输入你的收入：");
scanf("%f",&salary);
if (salary<750)
tax=salary*0.01;
if (salary<2250)
tax=7.50+(salary-750)*0.02;
if (salary<3750)
tax=37.50+(salary-2250)*0.03;
if (salary<5250)
tax=82.50+(salary-3750)*0.04;
if (salary<7000)
tax=142.50+(salary-5250)*0.05;
if (salary>7000)
tax=230.00+(salary-7000)*0.06;

printf("收入\$%f需交税\$%f",salary,tax);
return 0;
}

``````

#第十题

``````
/*
* @Author: 曾钰芝
* @Date: 2020-12-06 14:01:12
* @LastEditTime: 2020-12-06 14:01:12
* @Description: In User Settings Edit
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\实验三10.c
*/
int main(void){
int a,b,c,d,max1,min1,max2,min2;
printf("请输bai入四位du整数zhi:");
scanf("%d %d %d %d",&a,&b,&c,&d);
if(a>b){
max1=a;min1=b;}
else{
max1=b;min1=a;}
if(c>d){
max2=c;min2=d;}
else{
max2=d;min2=c;}
if(max1<max2)
max1=max2;
if(min1>min2)
min1=min2;
printf("最大值dao是%d\n",max1);
printf("最小zhuan值是%d\n",min1);
return 0;
}

``````

#第十一题

``````
/*
* @Author: 曾钰芝
* @Date: 2020-12-06 14:01:12
* @LastEditTime: 2020-12-06 14:01:12
* @Description: In User Settings Edit
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\实验三11.c
*/
#include<stdlib.h>

int schedule[]={
{8*60+0,10*60+16},/*08:00 =>10:16*/
{9*60+43,11*60+52},
{11*60+19,13*60+31},
{12*60+47,15*60+0},
{14*60+0,16*60+8},
{15*60+45,17*60+55},
{19*60+0,21*60+20},
{21*60+45,23*60+58}
};
int except;
int cmp(const void*a ,const void*b){
int m= ((int*)a);
int n= ((int*)b);
return abs(m-except)-abs(n-except);
}
void time_convert(int timestamp,char* s){
sprintf(s, "%d:%02d %c.m.",timestamp/60%12, timestamp%60,timestamp<720?'a':'p');
}

int main(void){
char from,to;
int hour,minute;

printf("Enter a 24-hour time:");
scanf("%d:%d",&hour,&minute);

except = hour*60 +minute;
qsort(schedule,sizeof(schedule)/sizeof(schedule),sizeof(schedule),cmp);
time_convert(schedule,from);
time_convert(schedule,to);

printf("Closest departure time is %s,arriving at %s.\n", from, to);

return EXIT_SUCCESS;
}

``````

#第十二题

``````
/*
* @Author: 曾钰芝
* @Date: 2020-12-06 14:01:12
* @LastEditTime: 2020-12-06 14:01:12
* @Description: In User Settings Edit
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\实验三12.c
*/
int main(){
int mm,dd,yyyy,mm1,dd1,yyyy1;
printf("Enter first date (mm/dd/yy):");
scanf("%d%d%d",&mm,&dd,&yyyy);
printf("Enter second date (mm/dd/yyyy):");
scanf("%d%d%d",&mm1,&dd1,&yyyy1);
if (yyyy>yyyy1)
printf("%d%d%2.2d is earlier than %d%d%2.2d",mm1,dd1,yyyy1,mm,dd,yyyy);
else if(yyyy=yyyy1)
if(dd>dd1)
printf("%d%d%2.2d is earlier than %d%d%2.2d",mm1,dd1,yyyy1,mm,dd,yyyy);
else if (dd=dd1)
if (mm>mm1)
printf("%d%d%2.2d is earlier than %d%d%2.2d",mm,dd,yyyy,mm1,dd1,yyyy1);
else
printf("%d%d%2.2d is earlier than %d%d%2.2d",mm,dd,yyyy,mm1,dd1,yyyy1);
else
printf("%d%d%2.2d is earlier than %d%d%2.2d",mm,dd,yyyy,mm1,dd1,yyyy1);
else
printf("%d%d%2.2d is earlier than %d%d%2.2d",mm,dd,yyyy,mm1,dd1,yyyy1);
return 0;
}

``````

#第十三题

``````
/*
* @Author: 曾钰芝
* @Date: 2020-12-06 14:01:12
* @LastEditTime: 2020-12-06 14:01:12
* @Description: In User Settings Edit
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\实验三13.c
*/
int main(){
int num,i;
i = 50;

while(i--){
printf("input a number\n");
scanf("%d",&num);

if(num>100||num<0)
{
printf("输入有误\n\n");
}
else{
switch(num/10){
case 10:
case 9:
printf("A\n\n");break;
case 8:
printf("B\n\n");break;
case 7:
printf("C\n\n");break;
case 6:
printf("D\n\n");break;
default:printf("成绩不合格\n\n");
}
}
}
}

``````

#第十四题

``````
/*
* @Author: 曾钰芝
* @Date: 2020-12-06 14:01:12
* @LastEditTime: 2020-12-06 14:01:12
* @Description: In User Settings Edit
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\实验三14.c
*/
int main()
{
int a,b,c;
printf("Scanf a int number:");
scanf("%d,&a");

if(a>=10 && a<20)
{
switch (a%10){
case 0:printf("ten");break;
case 1:printf("eleven");break;
case 2:printf("twelve");break;
case 3:printf("thirteen");break;
case 4:printf("forrteen");break;
case 5:printf("fifteen");break;
case 6:printf("sixteen");break;
case 7:printf("seventeen");break;
case 8:printf("eighteen");break;
case 9:printf("nineteen");break;

}
}
else{
switch(a/10){
case 2:printf("twenty");break;
case 3:printf("thirty");break;
case 4:printf("fourty");break;
case 5:printf("fifty");break;
case 6:printf("sixty");break;
case 7:printf("seventy");break;
case 8:printf("eighty");break;
case 9:printf("ninety");break;
}
}
printf("-");//打印“-”符号
switch (a%10){
case 0:printf("zero");break;
case 1:printf("one");break;
case 2:printf("two");break;
case 3:printf("three");break;
case 4:printf("four");break;
case 5:printf("five");break;
case 6:printf("six");break;
case 7:printf("seven");break;
case 8:printf("eight");break;
case 9:printf("nine");break;
}
return 0;
}

``````

https://my.oschina.net/u/4776602/blog/4776955