Mngaro Mwazenje

Mngaro Mwazenje

  • NA
  • 80
  • 13.1k

search array n give index

Mar 2 2020 5:22 AM
  1. using System;  
  2. using System.Collections.Generic;  
  3.   
  4. namespace exercise_79  
  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[10];  
  12. array[0] = 6;  
  13. array[1] = 2;  
  14. array[2] = 8;  
  15. array[3] = 1;  
  16. array[4] = 3;  
  17. array[5] = 0;  
  18. array[6] = 9;  
  19. array[7] = 7;  
  20.   
  21. Console.WriteLine("Search for?");  
  22. int searching = Convert.ToInt32(Console.ReadLine());  
  23.   
  24. // Implement the search functionality here  
  25. }  
  26.   
  27. }  
  28. }  
The exercise template has already an array containing numbers. Complete the program to ask the user for a number to search in the array. If the array contains the given number, the program tells the index containing the number. If the array doesn't contain the given number, the program will tell the number wasn't found.

Answers (4)