Put a mind map of yourself first.
Then, write two code that you've knocked over.
Array Manager, collection Manager
/*make an array parser * 1. Create an array * 2. Ascending order * 3. Output array * 4. Looking for odd number * 5. Finding prime numbers */ int[] nums; intLen; #regionCreate an array while(true) {Console.Write ("Please enter the length of the array (0-9999):"); Len=int. Parse (Console.ReadLine ()); Nums=New int[Len]; if(Len >=0&& Len <=9999) { Break; } Else{Console.WriteLine ("input error, enter continue input"); Console.ReadLine (); Console.clear (); } } for(inti =0; I < Nums. Length; i++) {Console.Write ("Please enter an array of"+ (i +1) +"Items:"); Nums[i]=int. Parse (Console.ReadLine ()); } #endregionconsole.clear (); #regionAscending order for(inti =0; I < Nums. Length-1; i++) { for(intj = i +1; J < Nums. Length; J + +) { if(Nums[i] >Nums[j]) { inttemp =Nums[i]; Nums[i]=Nums[j]; NUMS[J]=temp; } } } #endregion #regionOutput arrayConsole.WriteLine ("the array you entered is sorted as follows:"); for(inti =0; I < Nums. Length; i++) {Console.Write (Nums[i]+" "); } Console.WriteLine (); #endregion #regionLooking for oddConsole.WriteLine ("among them, the following numbers are odd:"); for(inti =0; I < Nums. Length; i++) { if(Nums[i]%2!=0) {Console.Write (Nums[i]+" "); }} Console.WriteLine (); #endregion #regionLooking for prime numbersConsole.WriteLine ("where the following numbers are prime numbers:"); for(inti =0; I < Nums. Length; i++) { BOOLIsfind =false; for(intj =2; J < Nums[i]; J + +) { if(nums[i]%j==0) {Isfind=true ; Break; } } if(!isfind) {Console.Write (Nums[i]+" "); } } #endregionConsole. ReadLine ();
/*Write a Collection Manager * Prompt menu and get user input menu options * Add data * Delete Data * Modify data * Ascending sort * Exit Program * Please select input (0-4)*/List<int> nums =Newlist<int>(); while(true) { #regionOutput Collection ContentsConsole.WriteLine ("the existing contents of the collection are as follows:"); Console.WriteLine ("==========================================================="); if(Nums. Count = =0) {Console.WriteLine ("no content in collection"); } Else { //traversing the output collection foreach(intIteminchnums) {Console.Write (item+"\ t"); } Console.WriteLine (); } Console.WriteLine ("==========================================================="); #endregion #regionPrompt menu, and get user-entered menu optionsConsole.WriteLine ("1. Add Data"); Console.WriteLine ("2. Delete Data"); Console.WriteLine ("3. Modify the Data"); Console.WriteLine ("4. Sort in ascending order"); Console.WriteLine ("0. Exit the program"); Console.Write ("Please select (0-4):"); intinput =int. Parse (Console.ReadLine ()); #endregion #regionAccording to the user's input, do different processingif(Input = =0) { Break;//exit loop, end of program } Else if(Input = =1) {Console.Write ("Please enter the number you want to add:"); intn =int. Parse (Console.ReadLine ()); Nums. ADD (n); } Else if(Input = =2) {Console.Write ("Please enter the number you want to delete (only the first occurrence is deleted):"); intn =int. Parse (Console.ReadLine ()); Nums. Remove (n); } Else if(Input = =3) { if(Nums. Count = =0) {Console.Write ("no data in the collection can be modified, press ENTER to continue"); Console.ReadLine (); } Else { intMaxindex =Nums. Count; Console.Write ("Please enter the number of items to modify ("+1+"-"+ (Maxindex) +"):"); intn =int. Parse (Console.ReadLine ()); if(N <0|| n >Maxindex) {Console.Write ("input Error, please enter the correct number of items, press ENTER to continue"); Console.ReadLine (); } Else{Console.Write ("Please enter the new data:"); intNewnum =int. Parse (Console.ReadLine ()); Nums[n-1] =Newnum; } } } Else if(Input = =4) { for(inti =1; I < Nums. Count-1; i++) { for(intj = i +1; J < Nums. Count; J + +) { if(Nums[i] >Nums[j]) { inttemp =Nums[i]; Nums[i]=Nums[j]; NUMS[J]=temp; } } } } Else{Console.Write ("input Error, please re-enter, press ENTER to continue"); Console.ReadLine (); } #endregionconsole.clear (); }
C # Fundamentals, basic points of knowledge, arrays and collections, and code