實現功能,一旦某一組裡面有一個成績在line_num以下的,就把這一組的數字都輸出。
代碼如下,改了好久還是沒發現問題出現在哪裡。
求教高手指點,非常感謝 >< ~
# include<stdio.h>
int main(){
float *search(float *(pointer)[3], float line);
float score[][3]={
{23, 56, 89},
{56, 12, 91},
{81, 73, 80},
{34, 62, 95}
};
float line_num;
int i;
float *p_addr;
printf("input the limit line:\n");
scanf("%f", &line_num);
p_addr=search(score, line_num);
printf("the student's scores are listed here:\n");
for(i=0; i<3; i++) printf("%f\t", *(p_addr+i));
putchar('\n');
return 0;
}
float *search(float *(pointer)[4], float line){
float *p_addr;
int i, j;
for(i=0; i<4; i++){
for(j=0; j<3; j++){
if(*(*(pointer+i)+j)<line) return p_addr=*(pointer+i);
}
}
}
好了,幫你改好了,請采納吧……
#include <stdio.h>
#include <stdlib.h>
float *search(float pointer[][3], float line);
int main() {
float score[][3] = {
{ 23, 56, 89 },
{ 56, 12, 91 },
{ 81, 73, 80 },
{ 34, 62, 95 }
};
float line_num;
int i;
float *p_addr;
printf("input the limit line:\n");
scanf("%f", &line_num);
p_addr = search(score, line_num);
printf("the student's scores are listed here:\n");
for (i = 0; i<3; i++) printf("%f\t", *(p_addr + i));
putchar('\n');
return 0;
}
float *search(float pointer[][3], float line) {
float *p_addr;
int i, j;
for (i = 0; i<4; i++) {
for (j = 0; j<3; j++) {
if (*(*(pointer + i) + j)<line)
return p_addr = *(pointer + i);
}
}
}
如果輸入為60,由於你的輸出為浮點型,所以輸出是23.000000 56.000000 89.000000