目录
7-1 比较大小 (15 分)
本题要求将输入的任意3个整数从小到大输出。
输入格式:
输入在一行中给出3个整数,其间以空格分隔。
输出格式:
在一行中将3个整数从小到大输出,其间以“->”相连。
输入样例:
4 2 8
输出样例:
2->4->8
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
int a,b,c,max;
scanf("%d %d %d",&a,&b,&c);
if (a>b){
max=a;
a=b;
b=max;
}
if(a>c){
max=a;
a=c;
c=max;
}
if(b>c){
max=b;
b=c;
c=max;
}
printf("%d->%d->%d",a,b,c);
return 0;
}
7-2 三天打鱼两天晒网 (20 分)
中国有句俗语叫“三天打鱼两天晒网”。假设某人从某天起,开始“三天打鱼两天晒网”,问这个人在以后的第N天中是“打鱼”还是“晒网”?
输入格式:
输入在一行中给出一个不超过1000的正整数N。
输出格式:
在一行中输出此人在第N天中是“Fishing”(即“打鱼”)还是“Drying”(即“晒网”),并且输出“in day N”。
输入样例1:
103
输出样例1:
Fishing in day 103
输入样例2:
34
输出样例2:
Drying in day 34
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
int N;
scanf("%d",&N);
if ((N%5)<=3&&(N%5)>=1){
printf("Fishing in day %d",N);
}
if ((N%5)==4){
printf("Drying in day %d",N);
}
if ((N%5)==0){
printf("Drying in day %d",N);
}
return 0;
}
7-3 分段计算居民水费 (15 分)
为鼓励居民节约用水,自来水公司采取按用水量阶梯式计价的办法,居民应交水费y(元)与月用水量x(吨)相关:当x不超过15吨时,y=4x/3;超过后,y=2.5x−17.5。请编写程序实现水费的计算。
输入格式:
输入在一行中给出非负实数x。
输出格式:
在一行输出应交的水费,精确到小数点后2位。
输入样例1:
12
输出样例1:
16.00
输入样例2:
16
输出样例2:
22.50
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
float x,m;
scanf(&#