Mngaro Mwazenje

Mngaro Mwazenje

  • NA
  • 80
  • 12.2k

swap arrays given by the user

Mar 2 2020 1:41 AM
  1. using System;  
  2. using System.Collections.Generic;  
  3.   
  4. namespace exercise_78  
  5. {  
  6. class Program  
  7. {  
  8. public static void Main(string[] args)  
  9. {  
  10. // DO NOT CHANGE THE FOLLOWING CODE!  
  11. int[] array = new int[5];  
  12. array[0] = 1;  
  13. array[1] = 3;  
  14. array[2] = 5;  
  15. array[3] = 7;  
  16. array[4] = 9;  
  17.   
  18. int index = 0;  
  19. while (index < array.Length)  
  20. {  
  21. Console.WriteLine(array[index]);  
  22. index++;  
  23. }  
  24. Console.WriteLine("");  
  25. // Implement here  
  26. // asking for the two indices  
  27. // and then swapping them  
  28. Console.WriteLine("Give two indices to swap: ");  
  29. int n = Convert.ToInt32(Console.ReadLine());  
  30. int t = Convert.ToInt32(Console.ReadLine());  
  31. // DO NOT CHANGE THE FOLLOWING CODE!  
  32. Console.WriteLine("");  
  33. index = 0;  
  34. while (index < array.Length)  
  35. {  
  36. Console.WriteLine(array[index]);  
  37. index++;  
  38. }  
  39. }  
  40. }  
  41. }
anyone with code how to swap user input arrays

Answers (1)