0 like 0 dislike
10.1k views

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) - asked in C
ID: 23560 - Available when: Unlimited - Due to: Unlimited
| 10.1k views
0 1
Called for Help
0 0
Called for Help
0 0
Called for Help

64 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>

#include<string.h>



int main()

{
** ** ** * * ** ***** * i=0, j, sum=0, average;
****** * * * ** *** ** data{
** ** ** ** * * * * * * ** * ** * **** * * *** * *** ** ** name[10];
** * ** ** ******* ** * *** ** ** *** ** **** * ** ** code;
**** ****** * * ***** *** * * *** * ** * ** * * ** grade;
* * * * ** * * **** *** * *** * * * *


** * ** * * * *** * * * ****
** * *** ** ** * * **** * * * ** ** * **** ** *** ** ** student[i].name);
* * ** *** ** * ***** * * **** ** * ** ** ** ** * * * * &student[i].code);
* * ***** ** * **** * * * ** ** * * ** * * * ** &student[i].grade);


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

    }


** * ******* *** * = sum/i;






* * * ** * ***** ** ***** * *
* ** ** * ****** * * * *** * * * * * ** *** *** *** %s\nCode: %d\nGrade: %d", student[0].name, student[0].code, student[0].grade);
* * * ** * * ** *
** * * ***** ** *
* *** * ** * * * * * * * ** * * ** * * ** ** * ** **** who got a higher grade than the average grade of all students:");
** ** * * * *** * * * ** * ** * *** **** * * * *** *
* *** * ** *** *** ** *** * ** ** ** * *** ** *** * ** *** **** *
** ****** ** ** * * * ** ** * * ** *** * ** ** *** **** * **** * ** ******* ** ** ** %s\nCode: %d\nGrade: %d", student[j].name, student[j].code, student[j].grade);
* * ** ** * * * * * * * * ** * ** ** ** ** ** *
** *** ***** **** * ** **** *

    }
* ****** * ** * * * 0;

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

#include<string.h>



int main()

{
** * ** * **** * ** * i=0, j, sum=0, average;
** ** ** * * *** * data{
** ** *** * * *** ** *** * ***** * * ** ** * * * * ****** * * *** *** * name[10];
* * *** **** *** *** * **** *********** ** * ** * code;
* * * * ** * **** * ** * * * * ** * * * * * * * ** * ** grade;
** ** * * *** * ** * * ***** * **** * **** *


* * *********** **** ** *** * * * * * * *
* * **** * * * * *** ** *** * * ** * *** * * ** ** * student[i].name);
* * * * * * *** * ** *** * ** * * *** ***** * * ** ** * &student[i].code);
* * ** * * * * * *** * * ** * *** ** * *** * * * * &student[i].grade);


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

    }


* * * ** * *** * * * * * = sum/i;
* * ***** ** ** *** ** * * ** * ***** * * i);






* * * * ****** * ** *
* * **** * ****** * * * ** ** * ** * * %s\nCode: %d\nGrade: %d", student[0].name, student[0].code, student[0].grade);
**** * ** * * * **
* * **** *** * *** *
** * ** * * **** ** * * ** * * * ***** * * * *** who got a higher grade than the average grade of all students:");
** ** ** ** **** *** ***** ** * ** * ** ***** ***** **
* * * * * * **** * * * * ** * * * *** * ** ** * ** * * ******** * * *
* ** ** ***** * **** ** **** **** * * * ***** * * * ** * * **** * ** **** ** *** **** ** ** **** %s\nCode: %d\nGrade: %d", student[j].name, student[j].code, student[j].grade);
* * * * * ** *** *** * ** * ******* * * * *** ** * * ** ***
* * ** ***** * * ******* * ** ** * * * * * * *

    }
* * *** * **** *** ** ***** 0;

}
answered by (-368 points)
0 like 0 dislike
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]);


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



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



int main()

{
** ** ** ** ****** * *** p1=0, p2=0, p3=0,i;
*** * *** ***** * ** * ** * ** &p1);
*** *** * *** * * *** * ** * ** * &p2);
**** * * **** ** * <= 0 || p1 >= 100)
* * ****** *** * **
*** *** * **** *** * ** * * *** ** * **** * *** * * ** ** * ** *** value");
* * * ** * ***** ** * *** * if(p2 <= 0 || p2 >= 100)
***** *** * *
* * ** * ** ** ** * * * ** *** ** * * * ** value");
* * * * *** * **** * ** * if(p1 > p2)
* * ** * ***
* ** * * ** * **** **** * * * **** ** ** ** * * *** ** * ***** value");
* * *** *** * * *** * *** ** {
* ** *** ***** ****** *** * ***** * *** * *** = p1+1; i < p2; i++)
* ** * *** ** *** ** * * * ** ******* * * *
* ** * * ** * *** ****** ** *** ** ** * * * ** * ** += i;
* * * *** **** ** ** * * **** * ** *
** ** * * **** * ***** * * * * ** ** *** * * ** **** p3);
** *** ** ** **** ****


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

}
answered by (237 points)
0 like 0 dislike
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]);
* ***** * *** * * * *** **** ** * * ** * * *** * *** * * * * *** **
***** ** * * * * * **** ** ** ** ** ***** *
***** **** *** * ******
** **** * * **** **

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



typedef struct classA{

    char name[50];

    int code;

    int grade;

}student;



int main(){

    int n;

    student list[100];

    while(1){

        int i;

        int stu=0;
* ** * ** ** * ** ***** **** ** * ** ** *** gradesum = 0;
**** ** *** * * * * ** **** *** *** *** * * * *** r;
** ** *** ***** * ** * * * ** * * **** **
* * * * * ***** ******* ** * *** * ** * **** ***** ******* ** ** * ** * ** * ** *** *** ****
** * * **** * * ***** ********* ***** * * **** * *** * ** * ** * ** ** *** *
* ** * * ** ** *** * * * * * *** ** * ** ** ** ** * ** * ** **** ******* * * * * *** * **
** * *** ******* **** ** * * * ** ** * ** ** * * **** ******* = stu + 1;
*** * * * * * * ** **** * * * ** * * ** *** ** * * * ** **** * ** * *
** * * * * * ***** * *** * *** * ****** * * * ** *** **** ****** * ** * * ** * * **** *
***** **** * *** * * ***** * **** * ****** **** * * ** ***** * * ** * **** **** * ** *** *** * = gradesum + list[i].grade;
** * * *** *** * ** *** ** * ** * * **** * * * * * ********* *** *****
****** ***** **** * *** ****** ** ** * * * ** **** *** * * ** * * * *** *** * *** = gradesum/(stu-1);


* ** ****** *** *** *** * *** * **** *** *** * * *** * * * ** * * * * ** * * * *** ****** **** * *** who got a higher grade than the average grade of all students:\n");
** * * * ****** * * * *** ****** *** **** * * * *** ** ** * * * **** ** * ** ** **** **** * **
** * * ****** * * ** ** * * ** * ** **** ***** *** * * * **** ** * ** ** * ** * *** * * * ** ** * ** ** *** ** * * > r){
*** * * * ** ** ********* * *** * **** ** * ** * *** * * ** ** * * ** * *** * ** ** * * ** ***** **** * *** ** * * ** * ***** ** *** *** %s\nCode: %d\nGrade: %d\n",list[i].name,list[i].code,list[i].grade);
**** * * ** ** ** * * *** *** * *** * * ** * * ** * ******** * ** ** *** *** * ** **** *** *** * *
**** * ** * * *** * ** ***** ** * ** *** * ** **** * * ** * ** *** * * ******* * * *
* * **** ** * ***** * ** * * ** ****** ** *** ** ** * ** ***** * ******** * * **
* * * *** * * **** ** * * ** * *** * ***** ** * * ***** * ** *** * * ***** * ** * 0;   
** *** * ** * **** * ** ** **** ***** **** ** * * ** * * * * ** * * ** * ** * * *** * **** * *
* *** * * *** * * * ** * **** ** * * * * * * * * ***** **

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

    return 0;   

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



struct inform

{
* *** **** * * ** * *** name[100];

    int ID;

    int grade;

};



void bubble(struct inform stu[],int n)

{
* ** *** ** ** ** * ** ** * inform QQ={0,0,0};
* ** * ** ** **** * * *** i,j;
* * *** * ** *** ** * *****

    {
** * * ** *** ****** * * * ** *** ** * ** *
** **** * *** ** ** ** ** * * * * * * * ** *
* *** *** * **** **** * * ** * ** **** **** * ** ***** * * *
* ** *** * ** ** **** * * * * ** ** **** * * ** ** *
** ** * ***** *** * * * * *** *** ** ***** * * * **** ** ** * **** ** *** * * * * ** ** * * ** *
** * ** ** ** ** * * * ** ** ******** *** ** *** ***** * ** * ***
* *** ** **** * ** * * * ** * * * ** *** * ** ** * *** **** ******* * *** ** **
** **** ** * * * * ******** *** ** ***** * **** ***** * **** * ** ** * ** ******** ** *
* * * * ** * ***** * ** * * * * * * ***** * * ****** ** *** ** ** ** * *** * ** * ** * = stu[i+1];
* ** ********* * *** * * * * * *** * * * * * *** * *** * ** ** * ** ** * * *** * ** **
** * * * * ** * * *** ** ************ * * * * ** **** ** ***** * * ** ** * *** * *** * ** * *** *
** ** **** ** * * * *** * * * * *** ** ** ** * * * * ** **** * *** *** ** ** *** *
** * ** * ********* * * * ***** * ** * *

    }
** ***** * ****** * ** *** ** stu[]];



}



void select(struct inform stu[],int n)

{
***** * * * * * * * * * sum=0;
* * * ** ** ********* * i;
* ** * ** * * *** * ** ***

    {
* ** * * ** *** * * *** * ** ** ** ** ***

    }
** * * *** **** ** * average=sum/n;






**** ** * ***** ** * * ** who got a higher grade than the average grade of all students:\n");


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

    {
*** * * * ** *** ** * **** * * * * *** * ** ** * * * *** *
** * * **** * ** * *** * *** ** * ** *** *
* * * **** ** * *** * * * * *** ***** * * * ** ** *** * ** * *** *** ** ** ** %s\n",stu[i].name);
** * ** *** * ** *** * ** * *** * * * * * * *** * * ***** * ** * ***** %d\n",stu[i].ID);
* ******** ** ** * ***** ** * ****** * ** * * *** *** * ** **** ** ** * * ** %d\n",stu[i].grade);
* * * * ** * *** * ** * * **** **** * * ** **



    }

}

int main(void)

 {
* *** **** ** ***** ***** inform stu[100];

    int n=0;
* * ** *** **** * * *** * * ** * **** *** **
*** ** **** ** ** ** ** ***** * * * * * * **** * *
** * ** * ** *** * * *** * ** *** * * **
** * * ** ** ** ******

    {
* * **** * ** * ** * **** * ** * * * *
** * * **** * * * * * ** ** ***** * ** ** *** * * *
* ***** * * * ** *** * **** * ** * * ** *** * * * * ** * * ** *** *
** ********** * ** **** * * *** ** * ** * *** * * * *

    }


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

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



struct student

{

char name[100];

int code;

int grade;



};





int average(struct student s[], int k)

{
* ** * ** * * * ** ** ** * * i;
****** ** ** ** ** * ** * sum=0;
** * ** * * * ** * ave;
* * * * * * *** *** * * * *
* *** ******* * * *
* ** * ** * * ** * **** * ** * ***** ** * **
* ** * * * ** * ** * * ** ** * * * ** **** * * * * * * * = %d\n",sum);
**** * * ** ** * * * ** **
* ***** * ** * * *** * *** **
* * *** * * * *** * * * ** ave;

}



void sort(struct student s[],int k)

{
* ** *** *** ** * i,j;
*** * * * *** ** **** = %d\n",k);
**** * * * * ** * student temp;
* * ** * * ** ** * * ** *** * *
* **** * **** *
* * * * * ** ** *** * * * ** ** ** *** ** ** *
* *** * **** * * * * ** * * * * *
** ** ** ** * * * * ***** * * ** ** * * * * * * ** **** ***** * * ** *** *** * ** *
* ** * *** ****** * ** ** * * * ** *** ** ** * * ** ****** * * * ** *
* * ** * * ** * *** * **** **** ** * * ***** ***** * *** * * * ** ****** *** ** *
* * ****** **** ** ** ** ** **** * *** * ****** * ** *** **** * * * ** * *** * *
** ** * * ****** * *** * ** ** ** ******* ** * ** ** ** *** *** ** ** * * * ** * * * * *
*** ** * ****** * * * * * * * ********* ****** * ***
* ** *** * **** ** *** ******** * * * * **
* * ** ** ** *** * *

}





int main()

{

int i,k;

int ave;



struct student s[100];



for(i=0;i<100;i++)

{
***** * * * * * * ** * * * * * **
*** * *** * *** ** ** **** *** * * ** ****
* * * *** ****** * * ***** ** * ** ****
** ** * *** *** *** ** * == -1)
* * **** *** ** * * ** * * ** * **** ***

}

k=i;

//printf("k=%d\n",k);

sort(s, k);

ave=average(s,k);

printf("Students who got a higher grade than the average grade of all students:");



for(i=0;i<=k;i++)

{
** * * ** ** * * * * ** ** *
*** * * * * ****** ** ** * **
*** * ** **** * * * * * **** *** * * * * * **** ** %s\n",s[i].name);
* ** *** * * * * * ** * * ** *** ** * ** * * * %d\n",s[i].code);
**** * * * * *** ****** **** * * **** * %d",s[i].grade);
* * ** *** * * * *

}

return 0;

}
answered by (-215 points)
0 like 0 dislike
Hidden content!
//

//  main.c

//  qwe

//

//  Created by 黃書垣 on 2017/4/9.

//  Copyright © 2017年 黃書垣. All rights reserved.

//



#include <stdio.h>

#include * * ** *



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){
* * ***** *** * * * * ***** *** ** * **** * * * * * ****** **** * ** ** ***** * **** *** * *
* ** *** * * *** * ** **** ********* ******* ** * * ** *** * * ** * * ** *** * * **
** * *** * ** ** * * * ***** * * * * * *** ***** ** * ** * ** * * * *** **** **
** ** ** * * ******* **** ** * * * * * * ****** **** *** *
* **** *** * * ** * ** ** * **** ** *** ** *
****** * ** * ** ***
** *** * *** * **

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



struct student

{

char name[100];

int code;

int grade;



};





int average(struct student s[], int k)

{
*** * ** *** ** *** ** * i;
** * * * *** ** **** sum=0;
*** * ** * * * * * ** *** ave;
* *** ** **** * ****** *** ** ** * *** * *
**** *** *** **** * ****
* **** **** * ***** * * * ** *** * *** * ** ***
**** ****** * * ** * * * * *** * * * * * * *** ** ** ** = %d\n",sum);
* ** * * * ** * * * *
*** * ** *** ** *** **
*** * ** * * * ** *** * *** ave;

}



void sort(struct student s[],int k)

{
* *** ** ** * * ** ** * * i,j;
* **** **** **** ***** * ** **** = %d\n",k);
* ** *** * *** *** * * ** student temp;
****** * ** *** * * *** * * ***
** * * ** **** ***
* *** * **** * ***** ** ** *** * * * **** * * ** * *
*** * * ** ** * * * * * * ** ** ** *** * * *
* * ****** * * *** * * ** * ** * * * * * * * * * * ** ** * *** * *
** * * * * *** ** *** * ** * * **** * * ** * ** *** * ***
** *** * * * ** ***** ** ******** * ** * **** *** * * ** *** * ***** *** * ** ** ** *
* * * ** ** * ******* *** *** ** * ** *** * * * * **** * *** * * *** *** * ** * *
* * ** * * ****** * ***** ** * ******* **** * * *** *** **** *** **** * **** ** * * * *** * **** **** **
*** * **** * ***** * * *** *** * ****** * * ** * ***** ** ** ****
**** ** * ** * * * *** * ***** * *** *
*** ** ** ** ** * **

}





int main()

{

int i,k;

int ave;



struct student s[100];



for(i=0;i<100;i++)

{
**** **** *** ** *** ***** * * ** *
* **** * *** ** ** * * * ******** *** **** * **** *
** *** ** * **** **** ***** ** * * * *
* ** * *** * ** * * **** *** == -1)
* * * *** *** ****** * ***** * ** ** * * **

}

k=i;

//printf("k=%d\n",k);

sort(s, k);

ave=average(s,k);

printf("Students who got a higher grade than the average grade of all students:");



for(i=0;i<=k+1;i++)

{
* * * ***** * * **** ***** * **
* **** * * ** **
*** * * ***** * **** ***** *** ** *** * ** ******* ** %s\n",s[i].name);
*** * ** * * * ** ** * * ** ** * ** ** * * ****** %d\n",s[i].code);
* * * * ** **** * *** * * **** *** ***** * * **** %d",s[i].grade);
* * ** *** * *

}

return 0;

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

Related questions

0 like 0 dislike
32 answers
[Exercise] Coding (C) - asked Apr 6, 2017 in C
ID: 23557 - Available when: Unlimited - Due to: Unlimited
| 5.9k views
0 like 0 dislike
18 answers
[Exercise] Essay (Open question) - asked Apr 20, 2017 in C
ID: 24219 - Available when: Unlimited - Due to: Unlimited
| 4.5k views
12,783 questions
183,442 answers
172,219 comments
4,824 users