Question

In: Computer Science

Complete the following C# code that declares an array of 7 integers. The application allows the...

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

Solutions

Expert Solution

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...


Related Solutions

C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements....
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements. Fill the array with random integers (use a loop). Neatly output each element in the one-dimensional array. Next convert your one-dimensional array of 24 elements into a two-dimensional array of 6 x 4 elements. Neatly output each element of the two-dimensional array. The values will be identical to the one-dimensional array – you’re just converting from one dimension to two.
Write a program in C that declares the following array: int. array[] = { 1, 2,...
Write a program in C that declares the following array: int. array[] = { 1, 2, 4, 8, 16, 32 } Then write some code that accepts a number between 0 and 5 from the user and stores it in a variable called "index". Write some code that retrieves the item specified by the index, like this: int item = array[index]; Then write code that outputs the corresponding array entry based on the number the user entered. Example output: The...
Complete the given C++ program (prob1.cpp) to read an array of integers, print the array, and...
Complete the given C++ program (prob1.cpp) to read an array of integers, print the array, and then find the index of the largest element in the array. You are to write two functions, printArray() and getIndexLargest(), which are called from the main function. printArray() outputs integers to std::cout with a space in between numbers and a newline at the end. getIndexLargest () returns the index of the largest element in the array. Recall that indexes start at 0. If there...
Provide code samples for the following in C#a. Declare a two-dimensional array of integers names...
Provide code samples for the following in C#a. Declare a two-dimensional array of integers names intArray17.b. Create a loop to calculate the sum of every element in the first column.c. Create a loop to calculate the sum of every element in the array.
In C# - Provide code samples for the following: Declare a two-dimensional array of integers names...
In C# - Provide code samples for the following: Declare a two-dimensional array of integers names intArray17. Create a loop to calculate the sum of every element in the first column. Create a loop to calculate the sum of every element in the array.
Write a program in C that does the following: 1. Declares an array called numbers_ary of...
Write a program in C that does the following: 1. Declares an array called numbers_ary of 6 integer numbers. 2. Declares an array called numbers_ary_sq of 6 integer numbers. 3. Reads and sets the values of numbers_ary from the keyboard using a loop. 4. Sets the values of numbers_ary_sq to the square of the values in numbers_ary using a loop. 5. Displays the values of numbers_ary and the values of numbers_ary_sq beside each other using a loop. Example Output Assume...
C Code Please! Declares a constant variable N and sets it to 42. * Declares an...
C Code Please! Declares a constant variable N and sets it to 42. * Declares an array of integers, with N elements, called fibonacci. * Declares an array of double floating-point numbers, with N-1 elements, called ratio. * Fills the fibonacci array with the numbers in the Fibonacci sequence (Wikipedia is your friend if you don't know what this sequence is about but you want to know).    Into the i-th element of the fibonacci array, you need to put...
*Java* Write an application that declares an array of three Listings whose contents are input by...
*Java* Write an application that declares an array of three Listings whose contents are input by the user (User inputs name and age for each listing). After the input, the listings should output in reverse order.
C++ Write the code to implement a complete binary heap using an array ( Not a...
C++ Write the code to implement a complete binary heap using an array ( Not a vector ). Code for Max heap. Implement: AddElement, GetMax, HeapSort, ShuffleUp, ShuffleDown, etc Set array size to 31 possible integers. Add 15 elements 1,3,27,22,18,4,11,26,42,19,6,2,15,16,13 Have a default constructor that initializes the array to zeros.. The data in the heap will be double datatype. PART 2 Convert to the program to a template, test with integers, double and char please provide screenshots thank you so...
write code to count the number of odd integers in an array of 100 random integers...
write code to count the number of odd integers in an array of 100 random integers in the range [0,99].
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT