Average value of integer numbers in the EXE 9 Statistics file (remove one of the largest and minimum values)

Source: Internet
Author: User
Tags integer numbers

# Include <iostream>
# Include <fstream>

Using namespace STD;

 

Int A [100]; // an array containing the integer read from the file
Int n = 0; // in the record Array

 

// Returns the maximum value in the array.

Int maxa (int A [], int N)
{
Int max = A [0];
For (INT I = 1; I <n; I ++)
{
If (A [I]> MAX)
Max = A [I];
}
Return Max;
}

 

// Returns the minimum value in the array.

Int Mina (int A [], int N)
{
Int min = A [0];
For (INT I = 1; I <n; I ++)
If (A [I] <min)
Min = A [I];
Return min;
}

 

 

Int main ()
{
Ifstream in ("score.txt", IOS: In );
If (! In)
{
Cerr <"Open File error! "<Endl;
Exit (1 );
}
// Read the numbers in the file into the Global Array a [] in sequence
While (in. Peek ()! = EOF)
In> A [n ++];
In. Close (); // close the file

Int sum = 0; // measure the size of the content in the array.
For (INT I = 0; I <n; I ++)
Sum + = A [I];
Int max = maxa (A, N );
Int min = Mina (A, N );
Float average = (Sum-max-min)/(n-2 );
Cout <"/> the average of the score is:" <average <Endl;
Return 0;
}

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.