0 thích 0 k thích
7.4k đã xem

Write a program with following requirements:

  • Define the structure type student with fields: name, code, and grade.
  • Write a function to sort the structures in grade ascending order and another function to display the data of the students who got a higher grade than the average grade of all students. If there is only 1 student in the list, display the data of that student.
  • Write a program that uses this type to read the data of 100 students and store them in an array of such structures. If the user enters the grade −1, the insertion of student data should terminate. Then print the data of the students who got a higher grade than the average grade of all students. 

 Example input:

Edgar
20161123
78
Robert
20161523
75
Rebecca
20166123
66
Todd
20161673
86
End
1
-1

Example output:

Students who got a higher grade than the average grade of all students:
Name: Edgar
Code: 20161123
Grade: 78
Name: Todd
Code: 20161673
Grade: 86

 

[Exercise] Coding (C) - đã hỏi trong C
ID: 23560 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 7.4k đã xem
0 1
Called for Help
0 0
Called for Help
0 0
Called for Help

64 Trả lời

0 thích 0 k thích
Hidden content!
#include <stdio.h>

#include <string.h>



struct student_grade{
*** ** *** ** ** ** * *** code[100],grade[100];
* * * ** ***** ** *** name[100][100];

};



int main()

{
*** * *** ** ** * * * sum=0;
** ***** ** ** *** *** i, j;
* * ***** ** ** student_grade s1;


* ** * * * ** ** * * ** ** * **** * **
* *** *** * * * ** ** * * ****** *** * * **** %d * **** * * * **** ** ** * * ** * ** **
* ** * * * *** * * * ** * ** *** ** * * == -1)
** ** ***** *** ** * ** * * *** * ***** * * ** * * **** * * ***
* * **** * ** * * * ******** * ** * * * ** * ******** *
*** **** * *** * *
* * * ** * * * * ** * /= (float)i;
** ***** *** * **** * * * * **** * who got a higher grade than the average grade of all students:\n");
* * * ** ******** *** * *** ** ** *
*** * **** * *** * * * * **** ** ** * * * * * * *** *** >= sum){
* ****** * * * *** * **** ** * * *** * * * *** ***** ** *** ** *** * %s\n",s1.name[j]);
**** * *** * ** ** * **** **** ** **** ** *** * * *** * **** *** ** * * ** * * %d\n",s1.code[j]);
* * * *** * ** ** ** * *** * *** * * * *** * **** * * ** *** * ** %d\n",s1.grade[j]);


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



}
trả lời bởi (-218 điểm)
0 thích 0 k thích
Hidden content!
#include <stdio.h>

#include <string.h>



struct student_grade{
** **** * * ** * *** ** code[100],grade[100];
* * *** ****** * ** *** * name[100][100];

};



int main()

{
** *** * * *** ** * ** sum=0;
****** * ** * * * *** * i, j;
* * ****** * *** * **** **** student_grade s1;


* * * ** * *** *** **** * * * ***** **** * *
* ** *** ** ** ** * * * * * ** ** * ** ** * ** %d *** * ** * * ** *** * *** * * * *
* * *** ** * ** * *** ** * **** == -1)
* *** * **** ** ***** ** ** * ** * ** ** * * **** * * * * * ******** * ***
** ** *** * * *** ** * * * *** **** * * * *****
** ******* *
* * ** *** ** * * * *** /= (float)i;
** * ** * ***** * ** *** ***** * ***** ** who got a higher grade than the average grade of all students:\n");
* *** *** ** * ****** * * ** ***
** ** ** ** ** * * ** * * ** * **** *** >= sum){
** * * * ** ** * ** * * * ** * **** **** * *** * * * **** ** * * *** %s\n",s1.name[j]);
**** * ** * * * * ** ** * ** * *** * * ** ** * * * * ** ** ** *** *** %d\n",s1.code[j]);
* * * * *** * **** * *** * * * **** * * **** * ** * *** * * * ** * ** *** ** * * * %d\n",s1.grade[j]);


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



}
trả lời bởi (44 điểm)
0 thích 0 k thích
Hidden content!
#include <stdio.h>

#include <stdlib.h>

#define MAX_STUDENT 3

#define MAX_NAME 10

#define MAX_ID 10



typedef struct{
* ** ** * * **** ** name[MAX_NAME], ID[MAX_ID];
* * * * ** **** ** * grade;

} stud;



int main(){
* ** * * ***** ** ** ** ** i, max=0, min=100;
* * ** * ****** **** ** students[MAX_STUDENT], *stuptr;


* * * * ** * * **** *
* * * ** * *** *** * ** * * **** != -1){
* * ** *** *** ** * *** **** * * * ** ** * * * * * ** * * stuptr->name);
*** * ** ** ** * ***** * *** * * ** **** * ** *** * stuptr->ID);
* ****** *** *** * *** ** * * * ** *** * * * ** * * * ****** *** &stuptr->grade);
* *** *** * *** ** *** * **** * ** * ***
******* * * * * *** ** *****
** *** * * * ** ***** * * * ** ** ** **
* *********** *** * * * * *** ** * * * ** * * * * * stuptr->name);
* * **** * * ** ** ** * **** * **** * **** ** * * ** * stuptr->ID);
* * * * ** **** * * * ** ** * *** ** *** ** ** * * ** &stuptr->grade);
****** ** ** * **** ****** * * ** ** ***** *
** **** * *** * ** ***
** * ** * ** *** ** * * **** * ** ****
* ** * ** * * * * *** * * i=0; i<MAX_STUDENT; i++,stuptr++)
** * * ** *
* * **** ***** * ** ** * ** ** * **** * > max)
** ** * * *** * * ** * * ** * *** ** *** * * * **** *** = stuptr->grade;
*** * * *** * * * **** *** * *** * ** * ** * * * *** ** * < min)
**** * *** * * *** ** ** * ** *** ** * * * *** * ** * ** ** * = stuptr->grade;
*** * *** * ** ***** * * *


* ****** * **** * * ***** ** * ** * i=0; i<; i++,stuptr++)
** ** * * * ** **** **
**** * * ** **** *** *** ***** * * * ** * ** * * * ** == max)
* ** * * ***** *** *** * **** * ** *** ** * * *
* * * ** * * **** *** * * ** * * * * * * * * ** *** * ** * %s %d", stuptr->name, stuptr->ID, stuptr->grade);
*** *** *** * *** *** * * ** ** **** * * * * * ** **** * *** * ** **
* * *** ** *** * * ******** *** ****** ** ** *****
* * * ***** * *** *** *
* * * * **** ** ** ** ** * * * * * i=0; i<5; i++,stuptr++)
* **** ** ***** **** *
* * * * ** ** ** * ** ***** *** ** ** ***** * ***** * == min)
****** * * ** ** * * ** * ** * ** *** *
* ** * ** * * * * * * ** * ** * **** * ** * *** ** * * * ***** * * * %s %d", stuptr->name, stuptr->ID, stuptr->grade);
* * **** ** * *** ** * ** * * *** *** ** * * * * * * ** ** * *
* * ******** ***** * * ** ** * * * ** **
* * ** * * * *
* ***** *** * ** **** 0;

}
trả lời bởi (44 điểm)
0 thích 0 k thích
Hidden content!
#include <stdio.h>

#include <stdlib.h>

#define MAX_STUDENT 3

#define MAX_NAME 10

#define MAX_ID 10



typedef struct{
*** * * * *** **** name[MAX_NAME], ID[MAX_ID];
** *** * ***** * ** * *** **** grade;

} stud;



int main(){
* * * * * * ** ** * i, max=0, min=100;
*** * ** ** **** * * students[MAX_STUDENT], *stuptr;


* **** * ********* * *** * ** ***
* * * ** * *** * ** *** * *** ** != -1){
* *** * * *** *** * ****** *** ***** * **** * *** ****** * stuptr->name);
* **** **** * ** **** *** * *** * * *** ** * * * *** ***** * stuptr->ID);
***** *** * ** * *** * ** ******* * *** *** * * ***** * * * &stuptr->grade);
** *** * * * ** * ** ** * * *** * *** * * ** **
** * * ** **** *** ****
** ******* ***** * ** *** ** * *** ***** **
** *** ***** *** ** * ** * * *** * * * ** * *** * ** stuptr->name);
* * *** * ** *** * ** ******** ** * ******* * * ** * ** **** * *** * stuptr->ID);
**** * *** * ** * * * * * ** ** **** ** * ** * * ********* &stuptr->grade);
* * * * * * *** *** * * ** * * ** **
* *** * * * * * * * ****
* * ** * * * * ** * **
**** * * * * ** * ** * *** ** ** * i=0; i<MAX_STUDENT; i++,stuptr++)
* *** ** * * * * * **
* ** ** * * * * * ** ** * ** * * * ** * **** * > max)
* ***** * *** ** * * * ** * ** ** * * * *** **** * = stuptr->grade;
*** **** * * * ** *** ** * ** **** * ***** ** ** ****** < min)
**** ** * **** * * * ** * ** ** ** ** ** * * *** * * * * * * * = stuptr->grade;
* * * ** * *** ***


* * * * **** * * ** * * ** ** * i=0; i<; i++,stuptr++)
** * * *** ** * * **
* * *** * * * ******** ** *** * *** * ** ** * *** * * == max)
**** ******* * ** * * * * * * *****
* ** * ***** *** * ** ** **** ** ** ***** ** ** * ** * ***** * ** %s %d", stuptr->name, stuptr->ID, stuptr->grade);
**** * * * ** ** * * * ** ** * * * ** ** ** ** ** ** * ** * * ** *
*** ** **** ***** *** * ** **** * *
* * * * *** * *** *
* * *** *** ** ** * * * * i=0; i<5; i++,stuptr++)
* * * ** * ** * * *
* *** ** ** *** * * ** * * * * * * * * * *** == min)
*** * *** **** *** * ** **** * * ** * **
** * ** ** * * * ***** * ********* *** ***** * ** ********* ** ** ** *** *** %s %d", stuptr->name, stuptr->ID, stuptr->grade);
* * ** ** ********** ** * * *** * * ***** ** ** ** *** * * * * * *** * ** * *
** * ** * * * *** **** ** ** * * **** ** **
** * ** * * * * *
* ** * ** * ** **** 0;

}
trả lời bởi (44 điểm)
0 thích 0 k thích
Hidden content!
#include <stdio.h>

#include <string.h>



struct student_grade{
*** ** ** ** ** ** *** ** code[100],grade[100];
** ****** ***** ** * name[100][100];

};



int main()

{
****** * * ** ***** * * * sum=0;
**** * * * * ** * * i, j;
* * * * * ** **** * ***** student_grade s1;


*** * ** * * * *** ** ** * *
** * * * **** * **** * * ** * * * **** ** ** * * %d *** * * * * * **** * *** *** * * * *** *
* *** ** * ** * * *** * * * * **** * == -1)
* * *** * ** * *** ***** * ** * ** ** ** ** ** * ** * ******* **** * *****
****** *** ** * ***** ** * ** * *** * * * **
** ** * ** ** *** * **
**** ****** **** ** ** /= (float)i;
* * * *** **** ** ** * * * * who got a higher grade than the average grade of all students:\n");
* *** ** * * ** * *** ** * *
**** * ** ** * * ** * * **** *** * ** *** * * * >= sum){
* * * ** * ** ** **** ******** ** **** ** ** **** ** *** ** * *** * ** * %s\n",s1.name[j]);
** ******* * *** * * ** * * * * * * * * * * * * * ** * *** * *** * **** %d\n",s1.code[j]);
** * * ** *** * ** * * * * ** * *** ** ** ** * ** * * * * * ***** ** * ** %d\n",s1.grade[j]);


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



}
trả lời bởi (20 điểm)
0 thích 0 k thích
Hidden content!
#include <stdio.h>

#include <string.h>



struct student_grade{
* ** * * ** ** ** * * * * code[100],grade[100];
* * *** * * * ** * name[100][100];

};



int main()

{
** *** *** ** **** ****** * sum=0;
* * ** **** * ** ** ** i, j;
*** * * * *** * **** * * student_grade s1;


* * * * * * * ***** ** * **
**** * ***** ** * * ** * * **** * ******* ** ** *** %d * * *** * ***** * **** ** ** * * ***
* * * * ** * * * **** ** ** *** * * * * * ** == -1)
*** * * * *** *** * * ****** * ** * ** *** * * ****** ***** * *** *** *
* *** * ** * * * ** ** * *********** *** ** **** * ** * * ** ** * **
****** ****** ***** * * **
* *** * * * * **** * * * ** /= (float)i;
* ***** ** * ** *** * * ****** ** *** who got a higher grade than the average grade of all students:\n");
***** * *** * * ** * *** * *
***** * * *** * *** * *** ** * ** * ***** >= sum){
** * * * * * ** * * ** ** * * ****** ** * *** *** ****** ***** *** ** %s\n",s1.name[j]);
** * * ** * * *** **** * ** * * ** ** * * * * ** ** **** * * ** %d\n",s1.code[j]);
**** **** ** * ** **** ** ** *** **** ***** * ** *** ** **** *** * * * ** *** %d\n",s1.grade[j]);


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



}
trả lời bởi (-48 điểm)
0 thích 0 k thích
Hidden content!
#include <stdio.h>

#include <string.h>



struct student_grade{
* * * *** * ** code[100],grade[100];
** * * * **** * ** * name[100][100];

};



int main()

{
* * * * * ******* * sum=0;
***** ** ****** ** i, j;
* ** * **** ** ** ** student_grade s1;


* ** * ** ** * * * * *** ****
* * * *** * * ** *** *** ** * ** * * ** * %d ** * **** ******* * * ** * * *** * *
* * *** * * ** ** * ** ******* * ** ***** * * * ***** == -1)
* * *** * * ** * * *** ** **** *** ** ** ******* **** * * * * ** ****
* ** * *** ** * * * ***** ** * *** ******** * * ******
** * ** *** *** * ***** *
* *** ** * ** ***** ** * ** /= (float)i;
* * * ** ** * * ***** * ** * * * who got a higher grade than the average grade of all students:\n");
* * ** * * ** * * ** * * **
* * ****** * *** * **** * * * ** * * * >= sum){
**** **** * * * ** * ** * ***** * ****** ** **** * * * * * * ** ** * ** * * %s\n",s1.name[j]);
**** ** * * **** * * * ** *** ****** * * ** *** *** ** * *** ** ** *** * * %d\n",s1.code[j]);
* * ** * * * ** ******** *** * * *** ** ** ** * *** ****** ** ** * * * ** * ** * * %d\n",s1.grade[j]);


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



}
trả lời bởi (38 điểm)
0 thích 0 k thích
Hidden content!
#include <stdio.h>

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



struct Student{
* *** ** ** ** * **** name[20];
** * * * * * ****** ** **** ID[20];
*** ** **** * * * * ** grade;

};



typedef struct Student Student;



int main(){
* * * * * *** ** * * i, lenght;
***** ** * **** * average = 0.0;
** * * * *** *** ***** list[100];
* ** ** *** ** ** * ****** i<100; i++){
** * * * ** *** * ** ** * ** *** * * **** * * * *** * list[i].name);
* ** *** * * * ** * * * * * ** ****** ** * * ** * * list[i].ID);
* ** ** * * **** **** ***** *** * **** * ************ *** * ** ** **** * *
* **** **** * * * * * **** * ** * ** ** * **** * ** ** * ** < 0)
*** * ** *** * ** ********* * * ** ** ** * * * * * ** ***** * ** *** ***
* * * * * * *
** ** * *** * ** *** * *
* *** * *** * * * = i;
* **** * ** * *** * ** i<lenght; i++){
** **** * *** * * **** *** * * * ** ** * * ** += list[i].grade;
***** * * ******** ****
* * ** *** * *** **
* ** * * ** * * * * ** = average / lenght;
*** ***** * * * * * * * * * **** * *** ** average);
*** * ** * * * **** *
* **** * ** * ***** ***** * **** who got a higher grade than the average grade of all students:\n");
** * * * *** *** ** * *** i<lenght; i++){
* * ** * ** * **** * * ** ** * ****** * * ** * * * * ** * > average){
* ** ** *** * * *** * ** * ** **** *** * ** * *** ** * * * * ** * * **** * %s\n", list[i].name);
** ** ** *** * * ** ** * * * * * * * ** ** * ** ** * * * ** ** %s\n", list[i].ID);
* *** * * ** ** **** ** **** * * * * *** ** * * ****** ** * * * *** * %d\n", list[i].grade);
** * * *** * *** * * * **** * ******
* * * * * ** ***
* * ** ** * ***** 0;

}
trả lời bởi (-188 điểm)
0 thích 0 k thích
Hidden content!
** * * **** ******
** MAX 100
* * * * * * * * *







struct student

{
*** * * ****** *** * * *** * **
** * * ****** **** ** code;
**** ** * * * *** *** grade;

};



void * * * * * ** * n)



{int i;
*** * j;


** * ** * (i = 0 ; i **** ** ( n - 1 ); i++)
* * * **
* * ** ** ** *** (j = 0 ; j ** * n - i - 1; j++)
* *** * *** ****** **** **
* * * * ***** * *** ** * * * * ** * * * * * ***** **
* *** ** *** * ** * * ** **
*** * * * *** * * * ***** ** *** *** **** * *** student temp * ** * e[j];
* ** * **** * * ** * * ** ** * * * * *** * * *** * * e[j+1];
* ** * ** *** * ** * *** ** * ** ***** ** ** = temp;




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









}



void *** * ** ** * * n)

{int avr=0;
** * * i;


* ***** **


* *** *** *



}
***


* * ** ****



if * * * *** * *
** * * ** **
* *** * * ** * * ** **** * **
* ** **** * ** ** * **** **

}

}





}

int main ()

{

struct ** *

int i;

int *** *

int n;



while ** * **



{



for ** **** *



{


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



}



}



}



n=i;



if * *


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



}



else
* **


* * * **










*** * 0;

}
trả lời bởi (-34 điểm)
0 thích 0 k thích
Hidden content!
* * * ** ** *
* * MAX 100








* * * **

{
* ** *** **** * **** ** **** ***
* * * **** **** ** *** code;
* * ** * **** * * ** * grade;

};



void * * student ** ** n)



{int i;
* *** * * j;


** ***** * * (i = 0 ; i * * * ( n - 1 ); i++)
* * *
*** * * * ** * **** * (j = 0 ; j ** ** n - i - 1; j++)
* * * ** * * * * ***
* *** ** * ***** * ** *** ** ** * * **
***** * * *** ** * ** * **
* * ** * * ** ** ** *** * ** ** * * student temp * * * * e[j];
*** * * * ******* ** * * ** * * * * * ** *** *** * * ** * *
** *** *** ** *** ** * ** *** * ** ** * *** ** = temp;
**** ** * * ** **** *****
* * * * ******* * *
*** * ** *









}



void ** * * ** *** * * n)

{int avr=0;
* * *** i;


** * ** **


** * **** ** *



}
**


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



if ** * * *
* * * * * * * *** **** **
* * *** * * ******* ** *
***** **** ** ** * ** ** *

}

}





}

int main ()

{

struct student **

int i;

int flag=0;

int n;



while **



{



for * * ** **



{


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



}



}



}



n=i;



if *


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



}



else
** * **
** *










**** 0;

}
trả lời bởi (-34 điểm)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.214.205
©2016-2025

Những câu hỏi liên quan

0 thích 0 k thích
32 trả lời
[Exercise] Coding (C) - đã hỏi ngày 6 tháng 4 năm 2017 trong C
ID: 23557 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 4.2k đã xem
0 thích 0 k thích
18 trả lời
[Exercise] Essay (Open question) - đã hỏi ngày 20 tháng 4 năm 2017 trong C
ID: 24219 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 3.1k đã xem
12,783 câu hỏi
183,442 trả lời
172,219 bình luận
4,824 thành viên