Professional Documents
Culture Documents
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.
C# Sharp Code:
using System;
Console.Write("----------------------------------------------------\
n");
n = Convert.ToInt32(Console.ReadLine());
for(i=0;i<n;i++)
arr1[i] = Convert.ToInt32(Console.ReadLine());
arr2[i] = arr1[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:
Sample Solution:-
C# Sharp Code:
using System;
int i, j, k;
Console.Write("-------------------------------------------------------
-----\n");
s1 = Convert.ToInt32(Console.ReadLine());
for(i=0;i<s1;i++)
arr1[i] = Convert.ToInt32(Console.ReadLine());
s2 = Convert.ToInt32(Console.ReadLine());
for(i=0;i<s2;i++)
arr2[i] = Convert.ToInt32(Console.ReadLine());
s3 = s1 + s2;
for(i=0;i<s1; i++)
arr3[i] = arr1[i];
for(j=0;j<s2; j++)
arr3[i] = arr2[j];
i++;
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;
Console.Write("\n\n");
Sample Solution:-
C# Sharp Code:
using System;
Console.Write("--------------------------------------------------\n");
n= Convert.ToInt32(Console.ReadLine());
for(i=0;i<n;i++)
arr1[i] = Convert.ToInt32(Console.ReadLine());
mx = arr1[0];
mn = arr1[0];
if(arr1[i]>mx)
if(arr1[i]<mn)
mn = arr1[i];
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: