Question one hundred and thirty-eight: pointer operations on student Structures

Source: Internet
Author: User

[Plain] # include <stdio. h>
# Include <stdlib. h>
 
Void print (struct students * p); // print the definition of the function print
Void max_score (struct students * p); // function max Definition
 
Struct students // definition of the struct students
{
Char number [15];
Float score;
};
 
Int main (int argc, char * argv [])
{
Struct students num [5] = {"121", 88.8 },{ "122", 77.7 },{ "123", 48.4 },{ "124", 99.1 }, {"125", 78.3 }};

Print (num );
Max_score (num );
 
System ("PAUSE ");
Return 0;
}
 
// Definition of function
 
// ** Print
Void print (struct students * p)
{
Int I;

I = 0;

While (I <5)
{
Printf ("% d student scored is % 0.2f \ n", I + 1, p [I]);
I + = 2;
}
}
 
// ** Max_score
Void max_score (struct students * p)
{
Struct students t; // used to save the maximum number of students
Int I;
Int j;

For (I = 0; I <4; I ++) // sort by score
{
For (j = 0; j <5; j ++)
{
If (p [I]. score> p [j]. score)
{
T = p [I]; // The student ID and score are also exchanged.
P [I] = p [j];
P [j] = t;
}
}
}

Printf ("The highest score is % f, and he number is % s \ n", p [0]. score, p [0]. number );
}

# Include <stdio. h>
# Include <stdlib. h>

Void print (struct students * p); // print the definition of the function print
Void max_score (struct students * p); // function max Definition

Struct students // definition of the struct students
{
Char number [15];
Float score;
};

Int main (int argc, char * argv [])
{
Struct students num [5] = {"121", 88.8 },{ "122", 77.7 },{ "123", 48.4 },{ "124", 99.1 }, {"125", 78.3 }};

Print (num );
Max_score (num );

System ("PAUSE ");
Return 0;
}

// Definition of function

// ** Print
Void print (struct students * p)
{
Int I;

I = 0;

While (I <5)
{
Printf ("% d student scored is % 0.2f \ n", I + 1, p [I]);
I + = 2;
}
}

// ** Max_score
Void max_score (struct students * p)
{
Struct students t; // used to save the maximum number of students
Int I;
Int j;

For (I = 0; I <4; I ++) // sort by score
{
For (j = 0; j <5; j ++)
{
If (p [I]. score> p [j]. score)
{
T = p [I]; // The student ID and score are also exchanged.
P [I] = p [j];
P [j] = t;
}
}
}

Printf ("The highest score is % f, and he number is % s \ n", p [0]. score, p [0]. number );
}

 

 
 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.