In: Computer Science
Complete the following C# code that declares an array of 7
integers. The application allows the user three
options:
l. to view the elements of array in reverse order, from the last
to first position,
2. to choose a specific position to view,
3. quit the program
using System;
class MainClass {
public static void Main (string[] args) {
int [] arr = new int[7] { 99, 8, 45, 89, 65, 63, 15};
int option,position,i;
while(true){
Console.WriteLine ("l. to view the elements of array in reverse
order, from the last to first position");
Console.WriteLine ("2. to choose a specific position to
view");
Console.WriteLine ("3. quit the program");
Console.Write("Select your option: ");
option = Convert.ToInt32(Console.ReadLine());
if(option == 1){
for(i =arr.Length-1;i>=0;i--){
Console.Write(arr[i]+" ");
}
Console.WriteLine("");
}else if(option == 2){
Console.Write("Enter a specific position to view: ");
position = Convert.ToInt32(Console.ReadLine());
if(position>7 || position <1)
Console.WriteLine("Invalid position");
else
Console.WriteLine ("The element at "+position+" is
"+arr[position-1]);
}else if(option == 3){
break;
}else{
Console.WriteLine ("Invalid option");
}
} // while close
} // main close
} //class close
Output :
NOTE: If you want to change something or any problem , please let me know through comments; I will surely revert back to you.
Please give a up vote .....
Thank you...