一、有一函数,当x<0时,y=-1;当x=0时,y=0.编写一个程序,输入一个x值,要求输出相应的y值
代码:
#include <stdio.h>
int result(int a);
int result(a)
{
if(a<0)
{
return -1;
}
else if(a==0)
{
return 0;
}
else
{
return 1;
}
}
int main()
{
int a,b=0;
scanf("%d",&a);
b=result(a);
printf("%d",b);
return 0;
}
二、要求按照考试成绩的等级输出百分制分数段,A等为85分以上,B等为70——84分,C等为60——69分,D等为60分以下。成绩等级由键盘输入。
代码:
#include <stdio.h>
int main()
{
int grade;
scanf("%d",&grade);
if(grade>=85)
{
printf("A");
}
else if(grade>=70&&grade<=84)
{
printf("B");
}
else if(grade>=60&&grade<=69)
{
printf("C");
}
else if(grade<60)
{
printf("D");
}
return 0;
}
三、写一个程序,判断某一年是否为闰年
提示:闰年即年份是4的倍数的,且不是100的倍数,世纪闰年则必须是400的倍数
#include <stdio.h>
int main()
{
int y;
scanf("%d",&y);
if((y%4==0&&y%100!=0)||y%400==0)
{
printf("yes");
}
else
{
printf("NO");
}
return 0;
}