zcmu1061-1073(记录)

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)/2

Input

见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;
}

 

 

  • 27
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: zcmu 1093 简单计算器是一道编程题目,要求实现一个简单的计算器,能够进行加、减、乘、除四种基本运算。该题目主要考察编程基础能力和算法思维能力,需要熟练掌握基本的运算符和控制语句,能够设计合理的算法实现计算器功能。 ### 回答2: zcmu 1093 简单计算器是一种基于计算机技术的工具,用于进行基本算术运算,如加减乘除等。它能够简化我们在日常生活中的计算工作,提高计算效率,减少出错率。 使用zcmu 1093 简单计算器非常简单,只需输入需要计算的数字和符号,就能够得到计算结果。它可以进行多个数字之间的复杂运算,同时还支持小数、百分数、平方根等复杂运算。另外,zcmu 1093 简单计算器还可以存储中间计算结果,方便我们进行多步计算或调整计算过程。 除了日常的计算工作,zcmu 1093 简单计算器还可用于科学计算、工程设计等领域。许多专业软件都是基于简单计算器原理设计的,它们具有更高的计算精度和更复杂的运算能力,能够支持更高级别的科学计算和技术分析。 总之,zcmu 1093 简单计算器在日常生活中有着广泛的应用,它使我们的计算工作变得更加高效、准确。并且,随着科技的不断发展,这种计算工具也在不断地更新和改进,为我们的计算工作提供更加便捷、多样化的选择。 ### 回答3: ZCMU 1093 简单计算器是一道基础的算法题目,需要实现一个简单的计算器程序,支持加、减、乘、除四种基本运算,可以对两个整数进行运算并输出结果。 要实现这道题目,首先需要根据输入的运算符来判断应该进行的运算类型,并根据运算符的不同,执行不同的计算操作。同时,应注意除数不能为零的情况,避免程序出现异常。 在编写程序的过程中,可以使用 switch case 语句来判断不同的运算类型,并执行相应的计算操作。同时,为了能有效地判断输入的运算符,可以使用输入字符串的方式进行处理,提取出运算符进行比较。 此外,在程序中还需要进行合法性判断,确保输入的数字均为整数且在合理的范围内,以避免程序运行出现异常情况。同时,还需要考虑输入格式的问题,应确保输入的数字和运算符符合题目要求。 综上所述,ZCMU 1093 简单计算器是一道基础的算法题目,需要实现一个简单的计算器程序,支持加、减、乘、除四种基本运算,注意程序的合法性判断和输入格式的处理,能够熟练地运用 switch case 等语句完成程序的编写。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值