第五次作业

1 编写程序,判断n是正数还是负数。

#include<stdio.h>

main()

{

   int n;

   printf("请输入一个数");

   scanf("%d",&n);

   if(n>0)

   printf("n是正数");

   else

   printf("n是负数");

 

 

}

 

 2 使用条件运算符,找出a,b,c,d,中最大的数。

#include<stdio.h>
main()
{
   double a,b,c,d,n1,n2,max;
   printf("请输入四个数");
   scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
   n1=a>b?a:b;
   n2=c>d?c:d;
   max=n1>n2?n1:n2;
   printf("%f",max);

   
}

 

 3 已知某商场搞促销,对于消费的价格有折扣活动,即消费1000打九折,消费2000打8.5折,消费3000打七折,消费5000打六折,编写程序求出消费者实际消费。

#include<stdio.h>
main()
{
   float price;
   printf("请输入消费金额");
   scanf("%f",&price);
   if(price>=5000)
       printf("实际支付:%.2f",price*0.6);
   else if(price>=3000)
       printf("实际支付:%.2f",price*0.7);
   else if(price>=2000)
       printf("实际支付:%.2f",price*0.85);
   else if(price>=1000)
       printf("实际支付:%.2f",price*0.9);
   else
       printf("实际支付:%.2f",price);
   
   
}

 

4 输入年,月,判断该月有多少天。

#include<stdio.h>
main()
{
    int year,month;
    printf("输入年和月");
    scanf("%d",&year,&month);
    switch(month){
    case 2:if(year%4==0&&year%100!=0||year%400==0)
               printf("29天");
       else 
           printf("28天");
       break;
       case 4:
       case 6:
       case 9:
       case 11:printf("30天");break;
       default:printf("31天");break;
    }

}

 

 5 输入三条边,是否能形成三角形。

#include<stdio.h>
main()
{
    int a,b,c;
    printf("输入三条边");
    scanf("%d%d%d",&a,&b,&c);
   if (a+b>c||a+c>b||b+c>a)
       printf("yes");
   else
       printf("no");

}

 

posted @ 2021-10-30 11:31  赵雅萌  阅读(27)  评论(0编辑  收藏  举报