这不是今年的题,但包括一部分,今年的题还没有加上去。
//1函数求值
#include "stdio.h"
int main()
{
int x,y;
printf("Please enter x:");
scanf("%d",&x);
printf("x=%d\n",x);
if(x<0||x>100)
y=-1;
else if(x=0)
y=0;
else
y=1;
printf("y=%d\n",y);
return 0;
}
//2.3个数排列顺序
#include "stdio.h"
int main()
{
float a,b,c,t;
printf("please a,b,c(并用空格隔开):");
scanf("%f%f%f",&a,&b,&c);
printf("比较前 a=%.2f b=%.2f c=%.2f\n",a,b,c);
printf("\n");
if(a
{
t=a;a=b;b=t;
}
if(a
{
t=a;a=c;c=t;
}
if(b
{
t=b;b=c;c=t;
}
printf("a,b,c大小顺序为:%.2f %.2f %.2f\n",a,b,c);
return 0;
}
//3.求4个数最大值和最小值
#include "stdio.h"
int main()
{
float max(float a,float b,float c,float d);
float min(float a,float b,float c,float d);
float a,b,c,d,Max,Min;
printf("please enter a,b,c,d:");
scanf("%f%f%f%f",&a,&b,&c,&d);
printf("a=%.2f,b=%.2f,c=%.2f,d=%.2f\n",a,b,c,d);
Max=max(a,b,c,d);
Min=min(a,b,c,d);
printf("max=%.2f\nmin=%.2f\n",Max,Min);
return 0;
}
float max(float a,float b,float c,float d)
{
float m;
float max(float a,float b);
m=max(a,b);
m=max(m,c);
m=max(m,d);
return m;
}
float max(float a,float b)
{
if(a>=b)
return a;
else
return b;
}
float min(float a,float b,float c,float d)
{
float m;
float min(float a,float b);
m=min(a,b);
m=min(m,c);
m=min(m,d);
return m;
}
float min(float a,float b)
{
if(a<=b)
return a;
else
return b;
}
//4.成绩等级
#include "stdio.h"
int main()
{
int score,k;
printf("please enter your score:");
scanf("%d",&score);
k=score/10;
switch(k)
{
case 9: printf("成绩等级:A\n");break;
case 8: printf("成绩等级:B\n");break;
case 7:printf("成绩等级:C\n");break;
case 6:printf("成绩等级:D\n");break;
case 5:case 4:case 3:case 2:case 1: case 0:printf("成绩等级:E\n");break;
default:printf("error!\n");
}
return 0;
}
//5.求函数值
#include "stdio.h"
int main()
{
float x,y;
printf("please enter x:");
scanf("%f",&x);
printf("x=%.2f\n",x);
if(x<1.00)
y=x;
if(x==10)
y=3*x-11;
if(x>=1&&x<0||x>10)
y=2*x-1;
printf("y=%.2f\n",y);
return 0;
}
//6.求300到400全部素数
#include "stdio.h"
#include "math.h"
int main()
{
int i,j=0,k,n=0;
for(n=301;n<=400;n=n+2)
{
k=sqrt(n);
for(i=2;i<=k;i++)
if(n%i==0) break;
if(i>=k+1)
{
printf("%5d",n);
j++;
}
if(j==5)
{printf("\n"); j=0;
}
}
printf("\n");
return 0;
}
//7.输出前Fibonacci数列20项
#include "stdio.h"
int main()
{
int f1,f2,f3;
int i;
int j=2;// 前两项不用参与变换,直接赋初值为2;
f1=1;
f2=1;
printf("%12d%12d",f1,f2);
for(i=0;i<18;i++)
{
f3=f2+f1;
printf("%12d",f3);
f1=f2;
f2=f3;
j++;//通过j的变化来控制换行;
{if(j%5==0)
printf("\n");
}
}
return 0;
}
//8.求n!+3前10相和数列
#inc