第五次作业

  1. 编写程序,判断学生的成绩是什么等级
    #include<stdio.h>
    main(){
        int score;
        printf("输入学生的分数\n");
        scanf("%d",&score);
        switch(score/10)
    {
        case 10:printf("A\n");break;
        case 9:printf("A\n");break;
        case 8:printf("B\n");break;
        case 7:printf("C\n");break;
        case 6:printf("D\n");break;
        default :printf("没通过\n");
    
                break;
    }

     

  2. 编写程序,根据x的值求y的值

    #include<stdio.h>
    main(){
        int x,y;
        printf("请输入x的值\n");
        scanf("%d",&x);
        if(x>0)
            y=x*x+1;
        else if(x==0)
            y=0;
        else if(x<0)
            y=-x*x+1;
       printf("y=%d\n",y);
    }

     

     

     

     

  3. 使用多分支结构,实现两个数的加减乘除
    #include<stdio.h>
    main(){
        float x,y;
        char f;
        printf("请输入表达式:\n");
        scanf("%f%c%f",&x,&f,&y);
        switch(f)
        {
        case '+':printf("x+y=%f\n",x+y);break;
        case '-':printf("x-y=%f\n",x-y);break;
        case '*':printf("x*y=%f\n",x*y);break;
        case '/':printf("x/y=%f\n",x/y);break;
                 }
    }

    4.输入年份判断是不是闰年。

    #include<stdio.h>
    main(){
        int x;
        printf("请输入年份:\n");
        scanf("%d",&x);
        if(x%4==0 && x%100!=0)
            printf("闰年");
        else if(x%400==0)
            printf("闰年");
        else
            printf("不是闰年");
    }

    5.编写程序,使用条件运算符找出三个数中最小的数字,并输出。

    #include<stdio.h>
    main(){
        int a,b,c,x;
        scanf("%d%d%d",&a,&b,&c);
        x=a<b?a:b;
        x=x<c?x:c;
        printf("%d",x);
    }

    6

    #include<stdio.h>
    main(){
        int m;
        scanf("%d",&m);
        if(m%4==0 && m%6==0)
            printf("");
        else
            printf("不能");
    }

     

     

     

     

     

     

     

     

posted @ 2021-10-27 21:53  张云月  阅读(19)  评论(0编辑  收藏  举报