You are on page 1of 15

1.

Write a program in C# Sharp to copy the elements one array into another
array. 
Test Data :
Input the number of elements to be stored in the array :3
Input 3 elements in the array :
element - 0 : 15
element - 1 : 10
element - 2 : 12
Expected Output:
The elements stored in the first array are :
15 10 12
The elements copied into the second array are :
15 10 12
Write a program in C# Sharp to copy the elements one array into another array.

Sensitivity: LNT Construction Internal Use


Sample Solution:-

C# Sharp Code:
using System;

public class Exercise4

public static void Main()

int[] arr1 = new int[100];

int[] arr2 = new int[100];

Sensitivity: LNT Construction Internal Use


int i, n;

Console.Write("\n\nCopy the elements one array into another


array :\n");

Console.Write("----------------------------------------------------\
n");

Console.Write("Input the number of elements to be stored in the


array :");

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

Console.Write("Input {0} elements in the array :\n",n);

for(i=0;i<n;i++)

Console.Write("element - {0} : ",i);

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

/* Copy elements of first array into second array.*/

for(i=0; i<n; i++)

arr2[i] = arr1[i];

/* Prints the elements of first array */

Console.Write("\nThe elements stored in the first array are :\n");

Sensitivity: LNT Construction Internal Use


for(i=0; i<n; i++)

Console.Write("{0} ", arr1[i]);

/* Prints the elements copied into the second array. */

Console.Write("\n\nThe elements copied into the second array


are :\n");

for(i=0; i<n; i++)

Console.Write("{0} ", arr2[i]);

Console.Write("\n\n");

Copy
Sample Output:
Copy the elements one array into another array :
----------------------------------------------------
Input the number of elements to be stored in the array :2
Input 2 elements in the array :
element - 0 : 2
element - 1 : 4
The elements stored in the first array are :
2 4
The elements copied into the second array are :
2 4
Flowchart:

Sensitivity: LNT Construction Internal Use


2. Write a program in C# Sharp to merge two arrays of same size sorted in
ascending order.
Test Data :
Input the number of elements to be stored in the first array :3
Input 3 elements in the array :
element - 0 : 1
element - 1 : 2
element - 2 : 3
Input the number of elements to be stored in the second array :3
Input 3 elements in the array:
element - 0 : 1

Sensitivity: LNT Construction Internal Use


element - 1 : 2
element - 2 : 3
Expected Output:
The merged array in ascending order is :
112233
Write a program in C# Sharp to merge two arrays of same size sorted in
ascending order.

Sample Solution:-

C# Sharp Code:
using System;

public class Exercise7

public static void Main()

Sensitivity: LNT Construction Internal Use


{

int[] arr1 = new int[100];

int[] arr2 = new int[100];

int[] arr3 = new int[200];

int s1, s2, s3;

int i, j, k;

Console.Write("\n\nMerge two arrays of same size sorted in


ascending order.\n");

Console.Write("-------------------------------------------------------
-----\n");

Console.Write("Input the number of elements to be stored in the


first array :");

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

Console.Write("Input {0} elements in the array :\n",s1);

for(i=0;i<s1;i++)

Console.Write("element - {0} : ",i);

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

Sensitivity: LNT Construction Internal Use


Console.Write("Input the number of elements to be stored in the
second array :");

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

Console.Write("Input {0} elements in the array :\n",s2);

for(i=0;i<s2;i++)

Console.Write("element - {0} : ",i);

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

/* size of merged array is size of first array and size of second


array */

s3 = s1 + s2;

/*----------------- insert in the third


array------------------------------------*/

for(i=0;i<s1; i++)

arr3[i] = arr1[i];

for(j=0;j<s2; j++)

arr3[i] = arr2[j];

i++;

Sensitivity: LNT Construction Internal Use


/*----------------- sort the array in ascending order
---------------------------*/

for(i=0;i<s3; i++)

for(k=0;k<s3-1;k++)

if(arr3[k]>=arr3[k+1])

j=arr3[k+1];

arr3[k+1]=arr3[k];

arr3[k]=j;

/*--------------- Prints the merged array


------------------------------------*/

Console.Write("\nThe merged array in ascending order is :\n");

for(i=0; i<s3; i++)

Console.Write("{0} ", arr3[i]);

Console.Write("\n\n");

Sensitivity: LNT Construction Internal Use


Copy
Sample Output:
Merge two arrays of same size sorted in ascending order.
------------------------------------------------------------
Input the number of elements to be stored in the first array :2
Input 2 elements in the array :
element - 0 : 1
element - 1 : 2
Inpu2 the number of elements to be stored in the second array :2
Input 2 elements in the array :
element - 0 : 3
element - 1 : 4
The merged array in ascending order is :
1 2 3 4
Flowchart:

Sensitivity: LNT Construction Internal Use


3. Write a program in C# Sharp to find maximum and minimum element in an
array. 
Test Data :
Input the number of elements to be stored in the array :3
Input 3 elements in the array :

Sensitivity: LNT Construction Internal Use


element - 0 : 45
element - 1 : 25
element - 2 : 21
Expected Output :
Maximum element is : 45
Minimum element is : 21

Write a program in C# Sharp to find maximum and minimum element in an array.

Sample Solution:-

C# Sharp Code:
using System;

public class Exercise9

public static void Main()

int[] arr1= new int[100];

int i, mx, mn, n;

Sensitivity: LNT Construction Internal Use


Console.Write("\n\nFind maximum and minimum element in an array
:\n");

Console.Write("--------------------------------------------------\n");

Console.Write("Input the number of elements to be stored in the


array :");

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

Console.Write("Input {0} elements in the array :\n",n);

for(i=0;i<n;i++)

Console.Write("element - {0} : ",i);

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

mx = arr1[0];

mn = arr1[0];

for(i=1; i<n; i++)

if(arr1[i]>mx)

Sensitivity: LNT Construction Internal Use


mx = arr1[i];

if(arr1[i]<mn)

mn = arr1[i];

Console.Write("Maximum element is : {0}\n", mx);

Console.Write("Minimum element is : {0}\n\n", mn);

Copy
Sample Output:
Find maximum and minimum element in an array :
--------------------------------------------------
Input the number of elements to be stored in the array :2
Input 2 elements in the array :
element - 0 : 20
element - 1 : 25
Maximum element is : 25
Minimum element is : 20
Flowchart:

Sensitivity: LNT Construction Internal Use


Sensitivity: LNT Construction Internal Use

You might also like