Question 5. 5. (TCOs 5, 6, 8) Write the C# code to for the following problem. De
ID: 672335 • Letter: Q
Question
Question 5.5. (TCOs 5, 6, 8) Write the C# code to for the following problem.
Declare an array to store five values; they could be decimal numbers.
Prompt the user to store values into the array.
Then prompt the user for a value to subtract from each element of the array.
Subtract that value from each element of the array and print the new values. Make sure you actually change the values in the array.
The output should look like this (note that it should work for any values that are input, these are just examples). You must use loop(s) to process the array.
Enter number: 10
Enter number: 20
Enter number: 30
Enter number: 40
Enter number: 50
Enter value to subtract: 5
After subtracting 5 the values are
5
15
25
35
45
Press any key to continue . . .
num = num + 1 (Points : 3) array
accumulator
counter
Not enough information given
Explanation / Answer
counter
elements
numbers[0] = 99
333555
public class ArrayExample
{
public static void Main()
{
double[] numbers = new double[5];
double number;
for(int i=0;i<5;i++)
{
Console.Write(“Enter number : ”);
number = Convert.ToDouble(Console.ReadLine());
}
Console.Write(“Enter value to subtract:”);
number = Convert.ToDouble(Console.ReadLine());
Console.Write(“After subtracting {0} the values are”,number);
for(int i=0;i<5;i++)
{
Console.WriteLine(numbers[i]);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.