20141020--Array

Source: Internet
Author: User

1             //The definition of the array, new is initialized, the length is "[]" in the number, assigned to "{}" within the content2             int[] Sz =New int[6] {1,2,3,4,5,6};//the array with the name SZ can be put in 6 int type number {curly braces write the number you want to write, separating}3             //An array of definitions, the number in the array is indexed, and the index starts at 0. 4             inti = sz[2];//Take out the value of an index in the SZ of this array, [2] is index number 2nd5             int[] sz1 =New int[6];//You can define a value without defining it in the following program .6sz1[0] =1;7sz1[1] =2;

Array, which is a combination of one type.

1.

1Console.Write ("Please enter the total number of classes:");2             intn =int. Parse (Console.ReadLine ());3             int[] sum =New int[n];4             inthe =0;5              for(inti =0; I <n; i++)6             {7Console.Write ("Please enter section"+ (i +1) +"Personal Score:");8Sum[i] =int. Parse (Console.ReadLine ());9he = he +Sum[i];Ten             } One             intm = Sum. Length;//defines m as the length of the sum of this array A             intPJ = he/m; -             intmax = sum[0]; -             intMin = sum[0]; the              for(intj =0; J < M; J + +) -             { -                 if(Sum[j] >max) -                 { +Max =Sum[j]; -                 } +                 if(Sum[j] <min) A                 { atMin =Sum[j]; -                 } -             } -Console.Write ("The average score is:"+ pj+"\ n Highest score:"+max+"\ n Minimum score:"+min); -Console.ReadLine ();

Bubble sort: (important content)

1Console.Write ("Please enter the total number of classes:");2             intn =int. Parse (Console.ReadLine ());3             int[] sum =New int[n];4             inthe =0;5              for(inti =0; I <n; i++)6             {7Console.Write ("Please enter section"+ (i +1) +"Personal Score:");8Sum[i] =int. Parse (Console.ReadLine ());9he = he +Sum[i];Ten             } One             intm = Sum. Length;//defines m as the length of the sum of this array A             intPJ = he/m; -             intmax = sum[0]; -             intMin = sum[0]; the              for(intj =0; J < M; J + +) -             { -                 if(Sum[j] >max) -                 { +Max =Sum[j]; -                 } +                 if(Sum[j] <min) A                 { atMin =Sum[j]; -                 } -             } -              for(intSX =0; SX < m; sx++)//In ascending order, define a SX, as an index of the array, starting from 0 -             { -                  for(intBJS = SX; BJs < M1; bjs++)//Compare BJS in ascending order.  in{//compares the value of the SX index to other values and replaces the largest value with the SX index -                     intZH = sum[sx];//Intermediate number en. Assigns the value on the index SX to the middle number en to                     if(SUM[SX] < SUM[BJS +1])//This is to compare the values on the SX index with all the values. +                     { -SUM[SX] = Sum[bjs +1];//assigns the largest value in the array to the SX index on the array sum thesum[bjs+1] = zh;//assigns the value of the middle number to the index where the original maximum value in the array sum is located *                     } $                 }Panax Notoginseng             } -Console.WriteLine ("The average score is:"+ PJ +"\ n Highest score:"+ Max +"\ n Minimum score:"+min); theConsole.WriteLine ("ascending order of fractions:"); +             foreach(intSxplinchSum//sort Sxpl in ascending order A             { theConsole.Write (SXPL +",");//print it by index.  +             } -Console.WriteLine (""); $Console.WriteLine ("descending order of fractions:"); $              for(intJXPL = m1; JXPL >=0; jxpl--)//defines the number of jxpl=m in the ordered array -             { -Console.Write (SUM[JXPL] +",");//Print in reverse order of the index.  the             } -Console.ReadLine ();

20141020--Array

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.