find and solve ||
Please wait.....

C# Single Dimensional Array

A single-dimensional array has only one dimension,thas is single-dimensional arrays are arrays with a single row of elements.Elements of a single-dimensional array in a console application:

1. Start Visual studio 2019 or other

2. Select File->New->Project from the menu bar.

3.Select Visual  C# console from the installed templates section in the left panel of the new project dialog box

4.Select Console Application from the middle panel to create a console application.

5.Enter the name of the application as SingleDimensionalArrays

6.Click the OK button to close the new Project dialog box and create the SingleDimensionalArrays

7.Add the code  as given below.

using System;
public class SingleDimensionalArrays
public static void Main()
Console.WriteLine("Hello World");
int[] marks = new int[3];
int totalMarks=0;
Console.WriteLine("Enter the marks in subject A:");
Console.WriteLine("Enter the marks in subject B:");
Console.WriteLine("Enter the marks in subject C:");
totalMarks=marks[0] + marks[1] + marks[2];
Console.Write("Total Marks: {0}",totalMarks);


Enter the marks in subject A:
Enter the marks in subject B:
Enter the marks in subject C:
Total Marks: 99

We first create a single-dimensional array,named marks,of the int data type that can store three elements.Next, we declare an int type variable ,toalMarks,and initialize it with the value,.After this,we prompt a user to enter the marks in three different subjects,on by on, and store the entered marks intoo the three array elements . Next , we add the values stored in the three array elements and assign the resultant value to the totalMarks variable .Finally,we display the value stored in the totalMarks  variable one the console.

8.Press the F5 key on the keyboard to run the application.The output of the application appears,prompting you to enter the marks in the first subject,
9.Enter the marks for the first subject,In this case,we have entered 20,
10.Press the ENTER Key on the keyboard.You are prompted to enter the marks in the second subject.
11.Enter as the marks for the second subject and then press the ENTER key.As a result ,sum of the marks in three subject is displayed on the console.
12.Enter 49 as the marks for the third subject and then press the ENTER key.As a result,sum of the marks in three subjects is displayed on the console,

Sundar  Neupane

Sundar Neupane

I like working on projects with a team that cares about creating beautiful and usable interfaces.


Report Response