练习03-18-02
有三个学生,四门课的成绩,要求在用户输入用户的学生序号以后,能输出该学生的全部学习成绩。
输出样例:
The matrix of scores:
12.00 11.00 52.00 79.00
86.00 67.00 55.00 59.00
77.00 16.00 20.00 88.00
Enter the number of the student:
2
The scores of NO.2 are:
77.00 16.00 20.00 88.00
--------------------------------
Process exited after 3.375 seconds with return value 0
请按任意键继续. . .
代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
float *search(float (*p)[4],int n);
int i,j;
float score[3][4];
srand((unsigned)time(NULL));
printf("The matrix of scores:\n");
for(i=0;i<3;++i){
for(j=0;j<4;++j){
score[i][j]=rand()%100;
printf("%7.2f",score[i][j]);
}putchar('\n');
}
printf("Enter the number of the student:\n");
int k;
scanf("%d",&k);
printf("The scores of NO.%d are:\n",k);
float *p=search(score,k);
for(i=0;i<4;++i){
printf("%7.2f",*(p+i));
}
return 0;
}
float *search(float (*p)[4],int n)
{
float *p1;
p1=*(p+n);
return p1;
}
输出成绩不及格学生的成绩
The matrix of scores:
18.00 81.00 65.00 30.00
49.00 44.00 63.00 14.00
35.00 27.00 64.00 32.00
The scores of No.1 are: 18.00 81.00 65.00 30.00
The scores of No.2 are: 49.00 44.00 63.00 14.00
The scores of No.3 are: 35.00 27.00 64.00 32.00
--------------------------------
Process exited after 0.05601 seconds with return value 7
请按任意键继续. . .
代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
float *search(float (*p)[4]);
int i,j;
float score[3][4];
srand((unsigned)time(NULL));
printf("The matrix of scores:\n");
for(i=0;i<3;++i){
for(j=0;j<4;++j){
score[i][j]=rand()%100;
printf("%7.2f",score[i][j]);
}putchar('\n');
}
float *p;
for(i=0;i<3;++i){
p=search(score+i);
if(p==*(score+i)){
printf("\nThe scores of No.%d are: ",i+1);
for(j=0;j<4;++j){
printf("%7.2f",*(p+j));
}
}
}
}
float *search(float (*p)[4])
{
float *p1=NULL;
int i;
for(i=0;i<4;++i){
if(*(*p+i)<60){
p1=*p;
break;
}
}
return p1;
}