WHAT ARE ARRAYS WRITE EXample CODE IN C#
Answers
Answered by
1
Heyyyy!!!!!
C turial for beginners.
for eg: programming language covering basis , literals data type, function, loops..
C turial for beginners.
for eg: programming language covering basis , literals data type, function, loops..
dharsan3:
which state
Answered by
0
Arrays works as collections of items, for instance strings. You can use them to gather items in a single group, and perform various operations on them, e.g. sorting. Besides that, several methods within the framework work on arrays, to make it possible to accept a range of items instead of just one. This fact alone makes it important to know a bit about arrays.
Arrays are declared much like variables, with a set of [] brackets after the datatype.
Write a program of sorting an array. Declare single dimensional array and accept 5 integer values from the user. Then sort the input in ascending order and display output.
Answer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Example1
{
class Program
{
static void printarray(int[] arr)
{
Console.WriteLine("\n\nElements of array are:\n");
foreach (int i in arr)
{
Console.Write("\t{0}", i);
}
}
static void Main(string[] args)
{
int[] arr = new int[5];
int i;
// loop for accepting values in array
for (i = 0; i < 5; i++)
{
Console.Write("Enter number:\t");
arr[i] = Convert.ToInt32(Console.ReadLine());
}
Program.printarray(arr);
//sorting array value;
Array.Sort(arr); //use array's sort function
Program.printarray(arr);
Console.ReadLine();
}
Arrays are declared much like variables, with a set of [] brackets after the datatype.
Write a program of sorting an array. Declare single dimensional array and accept 5 integer values from the user. Then sort the input in ascending order and display output.
Answer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Example1
{
class Program
{
static void printarray(int[] arr)
{
Console.WriteLine("\n\nElements of array are:\n");
foreach (int i in arr)
{
Console.Write("\t{0}", i);
}
}
static void Main(string[] args)
{
int[] arr = new int[5];
int i;
// loop for accepting values in array
for (i = 0; i < 5; i++)
{
Console.Write("Enter number:\t");
arr[i] = Convert.ToInt32(Console.ReadLine());
}
Program.printarray(arr);
//sorting array value;
Array.Sort(arr); //use array's sort function
Program.printarray(arr);
Console.ReadLine();
}
Similar questions