20141020--Array Exercise 1

Source: Internet
Author: User
Tags ticket

1             //1.. Enter 10 person's score minus two highest score two minimum points, averaging2Console.Write ("Please enter the total number of classes:");3             intn =int. Parse (Console.ReadLine ());4             int[] sum =New int[n];5             inthe =0;6              for(inti =0; I < n; i++)7             {8Console.Write ("Please enter section"+ (i +1) +"Personal Score:");9Sum[i] =int. Parse (Console.ReadLine ());Tenhe = he +Sum[i]; One             } A             intm = Sum. Length;//defines m as the length of the sum of this array -              for(inti =0; I < m; i++) -             { the                  for(intj = i; J <m-1; J + +) -                 { -                     intZhong =Sum[i]; -                     if(Sum[i] < Sum[j +1]) +                     { -Sum[i] = sum[j +1]; +Sum[j +1] =Zhong; A                     } at                 } -}//The two maximum values in the array are sum[0] and sum[1], and the minimum value is sum[m-1] and Sum[m] -             intg =sum. Length; -             intPJ1 = (he-sum[0]-sum[1]-sum[m-1]-sum[m-2])/(M-4); -Console.Write ("the average score for removing the two highest and two lowest points is"+pj1); -Console.ReadLine ();

1             //2... five candidates, 20 voted for the highest votes2Console.WriteLine ("the names of candidates are as follows: \ n 0, a 1, b 2, c 3, Ding 4, E");3Console.Write ("Please enter the total number of people participating in the poll:");4             intn =int. Parse (Console.ReadLine ());5             int[] BZ =New int[5] {0,0,0,0,0 };6              for(inti =0; I < n; i++)7             {8Console.Write ("Please enter section"+ (i +1) +"Number of individual tickets (0-4):");9                 intm =int. Parse (Console.ReadLine ());//the value entered must be an integer between 0-4, m=0 or M=1Ten                 if(M >=0&& m <=4) One{//if the input is m=0, then bz[0] (the value on the No. 0 index of the array BZ) +1 A                     //if the input is m=1, then bz[1] (the value on the 1th index of the array BZ) +1 -BZ[M] = Bz[m] +1; -                 } the                 Else -                 { -Console.Write ("input error, as invalidated"); -                 } +             } -             //here's how to find the maximum value +             intMax =0;//easy to print the most votes below A             intNa =0;//The purpose of defining NA is to position the maximum value.  at              for(inti =0; I <=4; i++) -             { -                 if(Bz[i] >max) -                 { -max = Bz[i];//if the value on index I of the array bz[] is greater than Max, assign this value to Max -na = i;//the value of Na is the index of the maximum value. Which is the value of I in                 } -             } toConsole.WriteLine ("the votes for 5 persons are \n0, respectively:"+ bz[0] +"\n1 candidate B votes:"+ bz[1] +"candidate C. \n2:"+ bz[2] +"candidate \n3:"+ bz[3] +"\n4, candidate E:"+ bz[4]); +Console.WriteLine ("the highest ticket is"+ Na +"number of candidates, the ticket is"+max); -Console.ReadLine ();

20141020--Array Exercise 1

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.