Question
An array is a collection of variables of the same type that are referred to by a common name. To declare a one-dimensional array, you
An array is a collection of variables of the same type that are referred to by a common name. To declare a one-dimensional array, you will use this general form:
type[ ] array-name = new type[size];
using System;
class MainClass {
public static void Main() {
int[] sample = new int[10];
int i;
for(i = 0; i < 10; i = i+1) sample[i] = i;
for(i = 0; i < 10; i = i+1)
Console.WriteLine("sample[" + i + "]: " +
sample[i]); } }
The general form for initializing a one-dimensional array is shown here:
type[ ] array-name = { val1, val2, val3, ..., valN };
using System;
class MainClass {
public static void Main() {
int[] nums = { 99, 10, 100, 18, 78, 23, 63, 9, 87, 49 };
int avg = 0;
for(int i=0; i < 10; i++)
avg = avg + nums[i];
avg = avg / 10;
Console.WriteLine("Average: " + avg); } }
Output:
Average 53
Assignment : Based on the examples, please create a code that initialize one dimensional array with the following set of numbers {45, 76, 8, 10, 34, 66, 87, 90, 13,26.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started