1.编码程序判断一个数是正数还是负数.

#include<stdio.h>

main()

{

int a;

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

scanf("%d",&a);

if(a>0)

          printf("%d是正数",a);

else

          printf("%d是负数",a);

}

第五次作业_#include

 

 第五次作业_#include_02

 

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

#include<stdio.h>

main()

{

   int a,b,c,d,max,sam,wan;

   printf("请输入四个数字");

   scanf("%d%d%d%d",&a,&b,&c,&d);

   max=a>b?a:b;

   sam=c>d?c:d;

   wan=max>sam?max:sam;

   printf("%d",wan);

}

第五次作业_条件运算符_03

 

 

3.已知某商场进行促销活动,对于消费的价格有折扣活动,即消费1000元打9折,消费2000元打8.5折;消费3000元打7折,消费5000元打6折,编写程序求出消费者实际的消费。

#include<stdio.h>                                                                  

main()

{

 float price;

 printf("请输入付款金额:");

 scanf("%f",&price);

 if(price>=5000)

 printf("实际需要支付:%.2f\n",price*0.6);

 else if(price>=3000)

 printf("实际需要支付:%.2f\n",price*0.7);

 else if(price>=2000)

 printf("实际需要支付:%.2f\n",price*0.85);

 else if(price>=1000)

 printf("实际需要支付:%.2f\n,price*0.9");

}

第五次作业_条件运算符_04

 

 

4.输入年份月份判断有多少天.

#include<stdio.h>

main()

{

int n[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int y,m;

printf("请输入年份:\n");

scanf("%d",&y);

printf("请输入月份:\n");

scanf("%d",&m);

if(y%4==0&&y%100!=0||y%400==0)n[1]=29;//闰年

printf("%d年%d月有%d天\n",y,m,n[m-1]);

}

第五次作业_it_05

 

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("不是三角形");

  else

  printf("是三角形");

}

第五次作业_it_06