第五次作业

1. #include<stdio.h>

main()

{

         int mark;

         printf("请输入学生的分数(0-100):\n");

         scanf("%d",&mark);

         switch(mark/10)

         {

         case 10:

         case 9:printf("A\n");

         case 8:printf("B\n");

         case 7:printf("C\n");

         case 6:printf("D\n");

         default:printf("NO PASS!\n");

         }

 

 

2.P58,案例三。

#include<stdio.h>

main(){

         float x,y;

         printf("请输入x的值:\n");

         scanf("%f",&x);

         if(x>0)

                  y=x*x+1;

         else if(x==0)

                  y=0;

         else

                  y=x*x*(-1)+1;

         printf("%f",y);

}

 

 

3.P63,案例八。

#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.练习册P43,1。编写程序,使用条件运算符找出三个数中最小的数字,并输出。

#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.P44,2.编写程序,判断整数m是否能被4和6同时整除。

#include<stdio.h>

main(){

         int m;

         scanf("%d",&m);

         if(m%4==0 && m%6==0)

             printf("能");

         else

                  printf("不能");

}

 

posted @ 2021-10-27 19:30  姚佳旭  阅读(24)  评论(0)    收藏  举报