Home > Back-end >  Question want to ask your bosses about pointer
Question want to ask your bosses about pointer

Time:12-14

Titled Tan Haoqiang c programming p292 T15, I write the code as follows (beginners code not good-looking sorry)
#include
Void aver (int (* p) [5]);
Void fail (int (* p) [5], int * pn, int x);
Void good (int (* p) [5], int * pn, int x);

Void aver (int (* p) [5])//for the first course score
{
Int I, j, sum=0;
For (I=0, j=0; i<20; I++)
{
If (I % 5==0) sum +=(* * p + I + j).
}
Sum=sum/4;
Printf (" the average of the first course can be divided into: % d \ n ", sum);
}


Void fail (int (* p) [5], int * pn, int x)//to find two students failed to pass the course, student id, and output results
{
Int I, j, flag;
for(i=0; i{
flag=0;
for(j=0; j<5; J++)
{
If (* (* (p + I) + j) & lt; 60) flag +=1;
}
If (flag>
=2){
Printf (" No. % d didn't pass the exam, all his achievements as follows: \ n ", * pn);
for(j=0; j<5; J++) printf (" % 5 d ", * (* (p + I) + j));
printf("\n");
}
}
}


Void good (int (* p) [5], int * pn, int x)//find the average score in 90 or above all result in more than 85 student
{
Int I, j, flag, sum, goodstudent [5].
Printf (" result outstanding student's student id is: ");
for(i=0; i{
Sum=0;
flag=0;
for(j=0; j<5; J++)
{
The sum +=(* * p + I + j).//here seems to be out of the question, cycle time, add the Numbers
Printf (" \ n \ nsumA=% d ", sum);
If (* (* (p + I) + j) & gt; 85) flag +=1;
}
If (flag==5) goodstudent [I]=* pn;
Else if (sum/4 & gt; 90) goodstudent [I]=* pn;
Printf (" sumB=% d ", sum);
}
for(i=0; i<4. I++) printf (" % 3 d, "goodstudent [I]);
}


Int main ()
{
Int I, j, score [4] [5], num [4].
Int * pnum, pscore (*) [5];
Printf (" please enter the student id: \ n ");
for(i=0; i<4. I++) the scanf (" % d ", & amp; Num [I]);
Pnum=& amp; Num [0].
for(i=0; i<4. I++ pnum++)
{
Printf (" please enter the % d student achievement: ", * pnum);
for(j=0; j<5; J++)
{
The scanf (" % d ", & amp; Score [I] [j]);
}
getchar();
}
for(i=0; i<4. I++)
{
for(j=0; j<5; J++)
{
If (score [I] [j] & gt; 100 | | score [I] [j] <0) printf (" % d row data is wrong! \ n ", I + 1);
}
}
Pscore=score;
Aver (pscore);
Pnum=& amp; Num [0].
Pscore=score;
Fail (pscore, pnum, 4);
Pscore=score;
Pnum=& amp; Num [0].
Good (pscore pnum, 4);
printf("\n");
return 0;
}

The following for running the results

Please enter the student id:
1 5 2 4
Please enter the student's grades: 1 90 90 90 90 90
Please enter the number 5 grades: 80 80 80 80 80
Please enter the 2 grades: 70 70 70 70 70
Please enter the 4 grades: 50 50 50 fifty
The first course is divided into: an average of 72
No. 4 didn't pass the exam, all his achievements as follows:
50 50 fifty
Achievement of outstanding students student number is:
SumA=90

SumA=181//90 + 90 + 1

SumA=273//90 + 90 + 90 + 2 + 1 somehow

SumA=366

SumA=460
SumB=460
SumA=90//the following repeated

SumA=181

SumA=273

SumA=366

SumA=460
SumB=460
SumA=90

SumA=181

SumA=273

SumA=366

SumA=460
SumB=460
SumA=90

SumA=181

SumA=273

SumA=366

SumA=460
SumB=460 1 5 2 4
Press any key to continue

Seek to reassure

CodePudding user response:

Modified as follows, for your reference:
 # include 

Void aver (int (* p) [5]);
Void fail (int (* p) [5], int * pn, int x);
Void good (int (* p) [5], int * pn, int x);

Void aver (int (* p) [5])//for the first course score
{
Int I, j, sum=0;
For (I=0, j=0; i<20; I++)
{
If (I % 5==0) sum +=(* * p + I + j).
}
Sum=sum/4;
Printf (" the average of the first course can be divided into: % d \ n ", sum);
}


Void fail (int (* p) [5], int * pn, int x)//to find two students failed to pass the course, student id, and output results
{
Int I, j, flag;
for(i=0; i{
flag=0;
for(j=0; j<5; J++)
{
If (* (* (p + I) + j) & lt; 60) flag +=1;
}
If (flag>
=2){
Printf (" No. % d didn't pass the exam, all his achievements as follows: \ n ", * pn);
for(j=0; j<5; J++) printf (" % 5 d ", * (* (p + I) + j));
printf("\n");
}
}
}


Void good (int (* p) [5], int * pn, int x)//find the average score in 90 or above all result in more than 85 student
{
Int I, j, k=0, flag, sum, goodstudent [5].//add a variable k
Printf (" result outstanding student's student id is: ");
for(i=0; i{
Sum=0;
flag=0;
for(j=0; j<5; J++)
{
The sum +=* (* (p + I) + j).//sum +=(* * p + I + j). There seems to be out of the question, cycle time, add the Numbers
//printf (" \ n \ nsumA=% d ", sum);
If (* (* (p + I) + j) & gt; 85) flag +=1;
}
If (flag==5 | | sum/5 & gt;=90) goodstudent [k++]=* pn;
//else
//if (sum/4 & gt; 90) goodstudent [I]=* pn;
//printf (" sumB=% d ", sum);
}
for(i=0; i}


Int main ()
{
Int I, j, score [4] [5], num [4].
Int * pnum, pscore (*) [5];

Printf (" please enter the student id: \ n ");
for(i=0; i<4. I++) the scanf (" % d ", & amp; Num [I]);

Pnum=& amp; Num [0].
for(i=0; i<4. I++ pnum++)
{
Printf (" please enter the % d student achievement: ", * pnum);
for(j=0; j<5; J++)
{
The scanf (" % d ", & amp; Score [I] [j]);
}
getchar();
}
for(i=0; i<4. I++)
{
for(j=0; j<5; J++)
{
If (score [I] [j] & gt; 100 | | score [I] [j] <0) printf (" % d row data is wrong! \ n ", I + 1);
}
}

Pscore=score;
Aver (pscore);//first class average

Pnum=& amp; Num [0].
Pscore=score;
Fail (pscore, pnum, 4);//two students failed to pass the course

Pscore=score;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related