1061: 求两个数的和与差
Description
输入整数 a 和b,计算并输出a、b 的和与差。
Input
输入只有一组a和b
Output
按照下面的例子输出结果
Sample Input
2 -8
Sample Output
The sum is -6 The difference is 10
#include<stdio.h> int main(void) { int a,b; scanf("%d %d",&a,&b); printf("The sum is %d\n",a+b); printf("The difference is %d",a-b); return 0; }
1062: 求平方根
Description
输入 1 个实数x,计算并输出其平方根(保留1 位小数)
Input
输入一个实数x
Output
输出平方根
Sample Input
17
Sample Output
The square root of 17.0 is 4.1
#include<stdio.h> #include<math.h> int main(void) { float x,y; scanf("%f",&x); y=sqrt(x); printf("The square root of %.1f is %.1f",x,y); return 0; }
1063: 华氏温度转换为摄氏温度
Description
输入华氏温度f,计算并输出相应的摄氏温度c(保留2 位小数)。c = 5/9(f-32).
Input
输入一个实数x表示华氏温度
Output
输出对应的摄氏温度
Sample Input
17.2
Sample Output
The temprature is -8.22
#include<stdio.h> int main(void) { float f,c; scanf("%f",&f); c=5.0/9.0; c=c*(f-32); printf("The temprature is %.2f\n",c); return 0; }
1064: 计算旅途时间
Description
输入 2 个整数time1 和time2,表示火车的出发时间和到达时间,计算并输出旅途时间。
有效的时间范围是 0000 到2359,不需要考虑出发时间晚于到达时间的情况。Input
输入只有两个整数
Output
求出火车的旅途时间
Sample Input
712 1411
Sample Output
The train journey time is 6 hrs 59 mins.
#include<stdio.h> int main() { int time1,time2; int h1,h2,h3,m1,m2,m3; scanf("%d %d",&time1,&time2); h1=time1/100; m1=time1%100; h2=time2/100; m2=time2%100; h3=h2-h1;m3=m2-m1; if(m3<0){ m3=60+m3; h3=h3-1; } printf("The train journey time is %d hrs %d mins.\n",h3,m3);
1065: 数字加密
Description
输入 1 个四位数,将其加密后输出。方法是将该数每一位上的数字加9,然后除以10 取余,
做为该位上的新数字,最后将第1 位和第3 位上的数字互换,第2 位和第4 位上的数字互
换,组成加密后的新数。Input
输入只有一个正整数
Output
输出加密后的新数
Sample Input
1257
Sample Output
The encrypted number is 4601
#include<stdio.h> int main() { int a,b,c,d,n1,n2; scanf("%d",&n1); a=(n1%10+9)%10;n1/=10; b=(n1%10+9)%10;n1/=10; c=(n1%10+9)%10;n1/=10; d=(n1+9)%10; n2=b*1000+a*100+d*10+c; printf("The encrypted number is %d",n2); return 0; }
1066: 大写字母转换成小写字母
Description
输入一个大写英文字母,输出相应的小写字母。
Input
输入一个大写英文字母
Output
输出对应的小写字母
Sample Input
K
Sample Output
k
#include<stdio.h> int main() { char c; scanf("%c",&c); if(c>='A'&&c<='Z'){ printf("%c",c+32); } else{ printf("%c",c); } scanf("%c",&c); return 0; }
1067: 显示两级成绩
Description
输入一个正整数 repeat (0<repeat<10),做repeat 次下列运算:
输入一个学生的数学成绩,如果它低于 60,输出“Fail”,否则,输出“Pass”。Input
见Sample
Output
见Sample
Sample Input
2 60 59
Sample Output
Pass Fail
#include<stdio.h> int main() { int repeat,i,n; scanf("%d",&repeat); for(i=1;i<=repeat;i++){ scanf("%d",&n); if(n<60){ printf("Fail\n"); }else{ printf("Pass\n"); } } return 0; }
1068: 找最小值
Description
输入一个正整数 repeat (0<repeat<10),做repeat 次下列运算:
输入四个整数,输出其中的最小值。Input
见Sample
Output
见Sample
Sample Input
3
12 6 1 90
10 40 30 20
-1 -3 -4 -5
Sample Output
min is 1
min is 10
min is -5
#include<stdio.h> int main() { int repeat,i,min; int a,b,c,d; scanf("%d",&repeat); for(i=1;i<=repeat;i++){ scanf("%d%d%d%d",&a,&b,&c,&d); if(a<b&&a<c&&a<d) min=a; else if(b<a&&b<c&&b<d) min=b; else if(c<a&c<b&&c<d) min=c; else min=d; printf("min is %d\n",min); } return 0; }
1069: 求三角形的面积和周长
Description
输入一个正整数 repeat (0<repeat<10),做repeat 次下列运算:
输入三角形的三条边 a, b, c,如果能构成一个三角形,输出面积area 和周长perimeter(保
留2 位小数);否则,输出“These sides do not correspond to a valid triangle”。
在一个三角形中,任意两边之和大于第三边。
三角形的面积计算公式:
aere*area = s(s-a)(s-b)(s-c)
其中:s = (a+b+c)/2Input
见Sample
Output
见Sample
Sample Input
4
5 5 3
1 1 4
4 1 1
1 4 1
Sample Output
area=7.15; perimeter=13.00
These sides do not correspond to a valid triangle
These sides do not correspond to a valid triangle
These sides do not correspond to a valid triangle
#include<stdio.h> #include<math.h> int main() { int repeat,m; float a,b,c,area,perimeter,s; scanf("%d",&repeat); for(m=1;m<=repeat;m++){ scanf("%f%f%f",&a,&b,&c); if(a+b>c&&b+c>a&&a+c>b){ perimeter=a+b+c; s=(a+b+c)/2; area=sqrt(s*(s-a)*(s-b)*(s-c)); printf("area=%.2f; perimeter=%.2f\n",area,perimeter); } else{ printf("These sides do not correspond to a valid triangle\n"); } } return 0; }
1070: 判断数的符号
Description
输入一个正整数 repeat (0<repeat<10),做repeat 次下列运算:
输入整数 x,若x 大于0,y=1;若x 等于0,y=0;否则,y=-1,最后输出y。Input
见sample
Output
见sample
Sample Input
3
2
-8
0
Sample Output
1
-1
0
#include<stdio.h> int main() { int repeat,i,x,y; scanf("%d",&repeat); for(i=1;i<=repeat;i++){ scanf("%d",&x); if(x>0){ printf("1\n"); }else if(x<0){ printf("-1\n"); }else{ printf("0\n"); } }return 0; }
1071: 计算个人所得税
Description
输入一个正整数 repeat (0<repeat<10),做repeat 次下列运算:
输入一个职工的月薪 salary,输出应交的个人所得税tax(保留2 位小数)。tax = rate * (salary-850)
当 salary <= 850 时,rate = 0;
当 850 < salary <= 1350 时,rate = 5;
当 1350 < salary <= 2850 时,rate = 10;
当 2850 < salary <= 5850 时,rate = 15;
当 5850 < salary 时,rate = 20;Input
见sample
Output
见sample
Sample Input
2
200
2000
Sample Output
tax=0.00
tax=115.00
#include<stdio.h> int main() { int repeat,i; float tax, rate ,salary; scanf("%d",&repeat); for(i=1;i<=repeat;i++){ scanf("%f",&salary); if(salary>5850){ rate=0.20; }else if(salary>2850&&salary<=5850){ rate=0.15; }else if(salary>1350&&salary<=2850){ rate=0.10; }else if(salary>850&&salary<=1350){ rate=0.05; }else if(salary<=850){ rate=0; } tax=rate*(salary-850); if(rate!=0){ printf("tax=%.2lf\n",tax); } else printf("tax=0.00\n"); } return 0; }
1072: 显示水果的价格
Description
输入一个正整数 repeat (0<repeat<10),做repeat 次下列运算:
以下 4 种水果的单价分别是3.00 元/公斤,2.50 元/公斤,4.10 元/公斤,10.20 元/公斤。
[1] apples
[2] pears
[3] oranges
[4] grapes
输入水果的编号,输出该水果的单价(保留2 位小数)。如果输入不正确的编号,显示单价为0.00。Input
见sample
Output
见sample
Sample Input
1
3
Sample Output
price=4.10
#include <stdio.h> int main () { int a, b, i, repeat, apples, pears, oranges, grapes; apples = 1; pears = 2; oranges = 3; grapes = 4; scanf("%d", &repeat); for (i = 1; i <= repeat; i++) { scanf("%d", &a); if (a == 1) { printf("price=3.00\n"); } else if (a == 2) { printf("price=2.50\n"); } else if (a == 3) { printf("price=4.10\n"); } else if (a == 4) { printf("price=10.20\n"); } else { printf("price=0.00\n"); } } return 0; }
1073: 字母转换
Description
输入一个正整数 repeat (0<repeat<10),做repeat 次下列运算:
输入一个字符,如果它是大写字母,输出相应的小写字母;如果它是小写字母,输出相应的
大写字母;否则,原样输出。Input
见sample
Output
见sample
Sample Input
3F=y
Sample Output
f=Y
#include<stdio.h> int main() { int repeat,n; char c; scanf("%d",&repeat); for(n=1;n<=repeat;n++){ scanf("%c",&c); if(c>='A'&&c<='Z'){ printf("%c",c+32); }else if(c>='a'&&c<='z'){ printf("%c",c-32); }else{ printf("%c",c); } }return 0; }