Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the C# code to for the following problem. Declare an array to store five v

ID: 3588864 • Letter: W

Question

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 multiply each element of the array.
Adjust the values 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 multiply by: 2
After multiplying by 2 the values are
20
40
60
80
100
Press any key to continue . . .

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace TestApplicat

{

    class Program

    {

        static void Main(string[] args)

        {

            int n1;

            int[] array = new int[5];

            for (int i = 0; i < 5; i++)

            {

                Console.Write("Enter number: ");

                array[i] = Convert.ToInt32(Console.ReadLine());

               

            }

            Console.Write("Enter value to multiply by: ");

            n1 = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("After multiplying by " + n1 + " the values are");

            for (int i = 0; i < 5; i++)

            {

                Console.WriteLine(array[i]*n1);

            }

         

        }

    }

}

Explanation / Answer


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestApplicat
{
class Program
{
static void Main(string[] args)
{
int n1;
float[] array = new float[5];
for (int i = 0; i < 5; i++)
{

Console.Write("Enter number: ");
array[i] = float.Parse(Console.ReadLine());

}

Console.Write("Enter value to multiply by: ");
n1 = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("After multiplying by " + n1 + " the values are");

for (int i = 0; i < 5; i++)
{

array[i] = array[i] * n1;

}
for (int i = 0; i < 5; i++)
{
Console.WriteLine(array[i]);
}

}
}
}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote