语言之条件语句练习题

第1关 判断平方和是否大于100

#include<stdio.h>
int main(void)
{
  /*********begin*********/
int a,b,x,y,q;
scanf("%d%d",&a,&b);
x=a*a+b*b;
y=a+b;

q=x/100;
if (x>100)
printf("%d",q);
else 
printf("%d",y);


  /*********end*********/
  return 0;
}

第2关 判断学生成绩等级

#include<stdio.h>
#include<math.h>
int main(void)
{
    /*********begin*********/
int  a,b;
scanf("%d",&a);
printf("成绩是%d,",a);
switch (a/10)
{
case 8:  b='A';break;
case 7: b='B' ;break;
case 6: b='C';break;
default :b='D' ;
}
printf("相应的等级是%c",b);
    /*********end*********/
    return 0;
}

第3关 判断是否为闰年

#include <stdio.h>
int main(void)
{
   /*********begin*********/
   int year,leap;
   scanf("%d",&year);
   if(year%4==0)
    if(year%100==0) 
     if(year%400==0) leap=1;
     else leap=0;
    else leap=1;
   else leap=0;
   if(leap) printf("%d年是闰年。",year);
   else printf("%d年不是闰年。",year);
   

 
   /*********end*********/
    return 0;
}

第4关 判断数字是否相同

#include<stdio.h>
int main(void)
{	
   /*********begin*********/
int x,a,b,c,d;
scanf("%d",&x);
a=x/100;
b=x%100/10;
c=x%10;
if((a==b&&b!=c)||(a==c&&c!=b)||(b==c&&a!=b)) d=1;
else d=0;
if(d) printf("1");
else printf("0");


   /*********end*********/
   return 0;
}

第5关 判断日期是一年中的第几天

#include<stdio.h>
int main(void)
{
   /*********begin*********/
int a,b,c,e,f;
scanf("%d-%d-%d",&a,&b,&c);
switch(b){
   case 1: e=0;break;
   case 2: e=31;break;
   case 3: e=59;break;
   case 4: e=90;break;
   case 5: e=120;break;
   case 6: e=151;break;
   case 7: e=181;break;
   case 8: e=212;break;
   case 9: e=243;break;
   case 10: e=273;break;
   case 11: e=304;break;
   case 12: e=334;break;}
e=e+c;
if((a%400==0)||(a%4==0&&a%100!=0)) f=1;
else f=0;
if(f==1&&b>2) e++;
printf("%d",e);

   /*********end*********/
   return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_64069699/article/details/130914157