Example: The average score of the total score is calculated by set.

Source: Internet
Author: User

static void Main (string[] args)
{
ArrayList al = new ArrayList ();//collection All types can be put into
Console.Write ("Please enter the number of people:");
int n = Convert.ToInt32 (Console.ReadLine ());//numeric type that turns the number of string types to integers
for (int i = 0; i < n; i++)//start loop. Cycle count equals number of people
{
Console.Write ("Please enter the" + (i + 1) + "score:"),//array subscript is starting from 0, so add 1
Al. Add (Convert.ToInt32 (Console.ReadLine ()));//Adds the object to the end of the arrylist and transforms it to place the score in the Al collection
}
Double sum = 0;
for (int b = 0; b < n; b++)//Calculate total Score
{
sum = sum + convert.todouble (al[b]. ToString ());
}
Double avg = sum/n;
Console.WriteLine ("Total score is" + sum);
Console.WriteLine ("Average divided" + avg);
Al. Sort ();//input sort order
Al. Reverse ();//Invert the command, execute it and turn it into descending order
for (int d = 0; d < n; d++)//output ranked score
{
Console.WriteLine (Al[d]);
}
Console.ReadLine ();

Example: The average score of the total score is calculated by set.

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.