0 like 0 dislike
4k views
有一個學生的結構如下

struct Student {

   int grade[20];

   int count;

};

grade 陣列裡儲存的是每位學生的成績, count 裡儲存的是該位學生共修習多少科目,請用這個結構實作以下函數。

int average_grade(struct Student s);

該函數傳入一個學生的結構,然後計算出該學生的平均後回傳。
[Exercise] Essay (Open question) - asked in 作業 by (18k points)
ID: 19748 - Available when: Unlimited - Due to: Unlimited

edited by | 4k views

20 Answers

0 like 0 dislike
Hidden content!
int **** ** *** Student s)

{
* * **** ** * * *** * ** i; ** ** * **** * * ** *** * counter
** *** ** ** *** ****** avg; *** *** record the average
* * ** * ** * ** *** ** * ** ** i++)
** * * ** *** **
** ** ** ** * * * ** ** *** * **** **** compute total score
*** ****** ** * * * ** * ******** * ** ** ** * += * *** *
** * * * * *** ** * * *
* * *** **** * ** /= s.count; * ** * ** * *** * ** ** get average score
* ** ** ** * * * (int)avg; * ** * **** **** * change data type and return

}
answered by (-248 points)
0 like 0 dislike
Hidden content!
#include **** * * *



#include * * ** *



#include ** * * *** *


* * * ** * ** **



struct Student {


* * *


* * * * * *** * *** ***


** * *


* *** * * * * * ** count;


** ****



};



int * *** * ** Student s)



{


* *


* * * * **** ** ******* i; ** ** ** ***


*


**** ** * *** average = 0,sum = 0;


** * **


** *** *** * * * * * (i = 0;i < *** ****


* * * *


* * ** ****** ** *


** **


* ***** **** * **** ** * *** * ** ** * *** * * += * * * ** ** * **


* *


* * ****** *** ** * ** ***


* *


** ** * ** ** * * ** * ** = sum / * * * *


* ***


* ** ** * * *** **** * *** ** * *** *


** *



}


***



int ** *


* * **



{


*


**** * * ** *** ** * i=0;


* * **


***** *** *** **** **** Student s;


* *


* * * * * * * * * * * ** ****** ****



*


* * ** **** ***** ********* * (i = 0;i < * **


**** * *


**** ** ***** ** * ** *** * ***** ** * * * * ****** ** * * ** * **


**



}





* * * ***


* ** * * * * *** * ** * * 0;


* *



}
answered by (102 points)
0 like 0 dislike
Hidden content!
int *** * **** * * ** a){
** * * * ***** * * = 0, total = 0;
* ** ** * * *** *** ** i = 0;


***** ** *** * = 0;i **** * * ++)
*** * * * *** ***** ** * *** *** = total + * * *


** ** * * * ** * ** = total / **** *


* *** * * * **** * ** * **

}
answered by (-122 points)
0 like 0 dislike
Hidden content!
***** ** * * * ** *

** *** ******* ***

* ** * ** ** *



struct student



{



* * ** * ** ** * ** ** grade[20];



* ** ** *** * * ** count;



* ****



int **** ** ** ** student s);



int main(void)



{



* * * * ** ** * * **** i;



* ***** * * * ** * **** student s;



** * * * *** * ** * * * ***** ** *  


** *** ** ***** *** * ** * * ** * * ***



* ***** * * * * * * ***** ** * ** *** * * * *** * * * ** * * * *



** * *** **** * ** * * **** ** * ** ** ******


* ** ** * ** * * * ** 0;



}



int **** ** ***** student s)



{



** *** * * * ** ****** * ** * * *



** * *** * *** * ** * **** ** * *



* * * ***** ** ** *** * * = sum + **** * *



** * * ** * * **** * * * = * *



* ** ** * * * * * * *** average;



}
answered by (-72 points)
0 like 0 dislike
Hidden content!
int average_grade(struct Student s)

{
** *** ** * * * *** *** i=0,j=0,k=0,r=0;
* * * ** * ***** ** ** **
* * * * *** ****** ** ** ** * ***
* ** * * * * *** ***** **** *
** **** * * * *
** ** * ** ***** * r;
***** * * * * *** *

}
answered by (-8 points)
0 like 0 dislike
Hidden content!
** * ** * *



struct Student {
* *** ** ** ***** * * grade[20];
* * * * * ** ** *** * count;



};



int ** ** Student *s) {
** * *** * * * * * * ** i=0, j=0, a;
* * ** * * * * * *** (i = 0; i < ** * * * * i++)
* ***** ** ** *** ** ** * * ***** * += * **
* * ** ** ** * = j / * * * *
***** **** ** * ** * * a;

}



int main() {
** * *** * ** ** * * ** Student t = {
* ** *** *** *** * * ** * * *** *** 100, 23, 33 }, 3
* ** **** * * ** * *
* ****** **** *** * * ****** ** ** ** * * ** **
* * ** * * ** * ** ** * * ** 0;

}
answered by (-105 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include <string.h>



struct Student {


* *** * ******** ** grade[20];


* ** * *** * ** * count;



};



int average_grade(struct Student s)

{


***** ** ******** i;
* **** * * *** ** *****
** ***** * * ** *** ** * average = 0,sum = 0;


** * * ** * * * * * ** (i = 0;i < s.count;i++)


* * * ** * ** ** **
* * * ** * **** * *** **** * ** * * *
** ** * * * ** **** ** * ** * * **** += (s.grade[i]);
* **** *** * ** * * * ** * ***** * **

// ** * * * ***** ** * * ** ** * * * ** **** * * ** ",sum);
** * ** ** ** ** ** * *** ** ** **
* *** ** * ***
**** *** * * ** *****
**** * * ** * *** * = sum / (s.count);
* ***** ** ** * * *
** **** ** **** *** * * * * *** * * * **** *



}



int main(void)

{
* ** * * * * *
* ** **** * * * ***** * i=0;
* * ** ** ** * *** *
** *** * * * ** *** Student s;
********* * ** * * ****
** * * ** * * * * * ** ***** * * * * *
* ** ** **** *

// * **** * * * * ** **** ** * ** ***** * *
* * *** * ***** * *
* * **** * **** (i = 0;i < s.count;i++){
** * * ****** ****
* ** * ** ****** * ** * * * * ***** ** * ** **** ** *
**** * *** * * ** ***

// * ** * **** * ** * * **** *** **** * * *
**** ** ** * ** * *

}


* * * ***** *** * **
* ** * ** *** *
** ** *** * * *** * * *** * 0;
*** * * ** ****

}
answered by (-157 points)
0 like 0 dislike
Hidden content!
**** * ***** * *

* ******* * * * * *

*** * *** *** *** **



struct student

{

* * * *** ** * * * grade[20];

* ** ** **** ** * * count;

 };



int * * *** * ** student s);



int main(void)

{

* *** * **** *** i;

******* * * * ** * * * student s;

** * * * ** * ** * * ***** *** ** ****** **  
* **** **** * * * *** ** ** * * * * * **

** * ** ** * * * * ** ** *** *** * *** ** *** * * * * * * ** * * *

*** ***** * * ** *** * * * ** * **
***** * * * ******* ** ** 0;

}



int ** ** ** * student s)

{

*** ** *** ** ** * *** * * * * ** * *

** ** * ***** * ** * ** * ** *

** * * ** *** *** = sum + s.grade[j];

** ***** *** ** ** = sum/s.count;

** *** * **** **** *** ** average;

}
answered by (-102 points)
0 like 0 dislike
Hidden content!
** ** * ***
* * * * ****
* * * ***** ***



struct Student

{
** ** * * * * ** * grade[20];
**** * ***** * ** * * ** * count;

 };



int ****** * **** Student s);



int main(void)

{

 int i;
* ** ** * ** * ** ** * Student s;
* ** ** * **** ** *** ** *

****** * ***** * * * *
*** * ***** ** ** ** * **** ** ***** **** * ** ***
* * * *** ****

* ** * * ** ** *** *** * *** ***********
** *** ** * * *** * * * * * 0;

}



int **** * * * Student s)

{
**** ** * * * ****** * ** ** * k,b=0;
* * ** ** * *** * * **** * ** *** ****
**** ****** *** ** **** *** = b+s.grade[k];
* ** ** * ** ** * * = b/s.count;
* ** *** ** ** *** * ** * ** * **** *

}
answered by (-136 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include * * *** ** ******

struct student

{
**** * * * * * * ***** grade[20];
** * * ** ** ******* *** count;

}s;

int main(void)

{
*** * ** * ** ** student s;
**** * * *** * **** * * grade[20];
* ****** ** * * * *** * * count;
** * ** ** * * * * * i;
*** * *** * * ***** * sum = 0;
* ***** * ** * * * * * ** * aver = 0;
* *** ********* * *** * ** * *** *** * * *
** ** * *** * ** * * = 1;i <= count;i++)
* * * ** *** **
** *** * * * * * * ** **** * * ** * *** * ** ***** * * * ***
*** * ** * ** ** * * ** ** * *** * ***** **** * ***** += grade[i] ;
****** ** *** **** ** *
** * ** * * ***** ** ** = sum / count;
** ** * * *** * ** * * **** * *
* * * *** *** * 0;

}
answered by (-320 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:104.23.197.95
©2016-2026

Related questions

0 like 0 dislike
3 answers
[Exercise] Essay (Open question) - asked Dec 21, 2016 in 作業 by Shun-Po (18k points)
ID: 19755 - Available when: Unlimited - Due to: Unlimited
| 1.2k views
0 like 0 dislike
9 answers
[Exercise] Essay (Open question) - asked Dec 21, 2016 in 作業 by Shun-Po (18k points)
ID: 19753 - Available when: Unlimited - Due to: Unlimited
| 2.5k views
0 like 0 dislike
0 answers
[Exercise] Essay (Open question) - asked Dec 28, 2016 in 作業 by Shun-Po (18k points)
ID: 20139 - Available when: Unlimited - Due to: Unlimited
| 718 views
0 like 0 dislike
82 answers
[Exercise] Coding (C) - asked Nov 23, 2016 in 作業 by Shun-Po (18k points)
ID: 17578 - Available when: Unlimited - Due to: Unlimited
| 11.9k views
0 like 0 dislike
26 answers
[Exercise] Essay (Open question) - asked Nov 9, 2016 in 作業 by Shun-Po (18k points)
ID: 17203 - Available when: Unlimited - Due to: Unlimited
| 4.8k views
12,783 questions
183,442 answers
172,219 comments
4,824 users