计算机二级考试 C语言
五、1、#include <stdio.h>
int min(int a,int b){
return (a<b?a:b);
} void main(){
int a,b;
scanf(“%d,%d”,&a,&b);
printf(“%d”,min(a,b)); }
2. #include <stdio.h>
void main(){
float score[10][5], stuave[10],courseave[5],fangcha;
float temp1,temp2;
int i,j;
printf(“Please input the scores :”);
for (i=0;i<10;i++){
stuave[i]=0; temp1=0; temp2=0;
for (j=0;j<5;j++){
scanf(“%f”,&a[i][j]);
stuave[i]+=a[i][j];
}
stuave[i]/=5.0; temp1+=stuave[i]*stuave[i]; temp2+=stuave[i];
}
for (j=0;j<5;j++){
courseave[j]=0;
for (i=0;i<10;i++)
courseave[j]+=score[i][j];
courseave[j]/=10.0;}
fangcha=temp1/n-(temp2/n)*(temp2/n);
printf(“the average scores of each student are: ”); for (i=0;i<10;i++) printf(“%5.2f”,stuave[i]); printf(“the average scores of each course are: ”); for (i=0;i<5;i++) printf(“%5.2f”,courseave[i]); printf(“the fangcha is %5.2f”,fangcha);
}
3、非递归方法
#include <stdio.h>
void main(){
int n,i=0;
long fac=1;
scanf(“%d”,&n);
while (i<n){
i++; fac*=i;
}
printf(“%ld”,fac);