C exercises and solutions: max and min scores


C structure: max and min scores

Step 9: Defining the showmax(student st[], int itemcount) and showmin(student st[], int itemcount) functions show about the student who gets the maximum score and the student who gets the minimum score. To find the highest total core or lowest total core, we need to compare every total score of each element. //function to show max total score
void showmax(student st[], int itemcount)
{
float max = st[0].total;
int index=0,j;
if (itemcount >= 2)
{

for (j = 0; j < itemcount-1; ++j)
if (max < st[j+1].total) {
max = st[j+1].total;
index = j+1;

}


}

else if (itemcount == 1)
{
index = 0;
max = st[0].total;
}


else printf("Not record found!\n");

if (index != -1) printf("The student with ID %s gets the highest score %f",st[index].stnumber,max);


}

//function to show min total score
void showmin(student st[], int itemcount)
{

float min = st[0].total;
int index = 0,j;
if (itemcount >= 2)
{
for (j = 0; j < itemcount-1; ++j)
if (min > st[j+1].total)
{
min = st[j+1].total;
index = j+1;

}

}

else if (itemcount == 1)
{
index = 0;
min = st[0].total;
}
else printf("No record found!\n");

if (index != -1) printf("The student with ID %s gets the highest score %f",st[index].stnumber,min);

}




Comments




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.