Tutorial 2 Arrray 21SOEIT11028
Tutorial 2 Arrray 21SOEIT11028
Abhay shukla
21SOEIT11028
1. Write a C# Sharp program that stores elements in an array and prints them..
Code :
using System;
public class Exercise1
{
public static void Main()
{
Console.WriteLine("Abhay");
int[] arr = new int[5];
int i;
Output:
2. 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.
Code :
using System;
public class Exercise11
{
public static void Main()
{
Console.WriteLine("Abhay");
int[] arr1 = new int[10];
int n, i, j, tmp;
Output:
3. Write a C# Sharp program to read n values in an array and display them in reverse order.
Code :
using System;
public class Exercise2
{
public static void Main()
{
Console.WriteLine("Abhay");
int i,n;
int[] a= new int[100];
4. Write a C# Sharp program to copy the elements of one array into another array.
Code :
using System;
public class Exercise4
{
public static void Main()
{
Console.WriteLine("Abhay");
int[] arr1 = new int[100];
int[] arr2 = new int[100];
int i, n;
Code :
using System;
public class Exercise5
{
public static void Main()
{
Console.WriteLine("Abhay");
int[] arr1 = new int[100];
int[] arr2 = new int[100];
int[] arr3 = new int[100];
int s1, s2, mm = 1, ctr = 0;
int i, j;
Console.Write("\n\n");
}
}
6. Write a C# Sharp program to find the maximum and minimum elements in an array.
Code :
using System;
public class Exercise9
{
public static void Main()
{
Console.WriteLine("Abhay");
int[] arr1= new int[100];
int i, mx, mn, n;
Console.Write("Input the number of elements to be stored in the array :");
n= Convert.ToInt32(Console.ReadLine());
mx = arr1[0];
mn = arr1[0];
if(arr1[i]<mn)
{
mn = arr1[i];
}
}
Console.Write("Maximum element is : {0}\n", mx);
Console.Write("Minimum element is : {0}\n\n", mn);
}
}
7. Write a program in C# Sharp to separate odd and even integers into separate arrays.
Code :
using System;
public class Exercise10
{
public static void Main()
{
Console.WriteLine("UTTAM SOJITRA");
int[] arr1 = new int[10];
int[] arr2 = new int[10];
int[] arr3 = new int[10];
int i,j=0,k=0,n;
for(i=0;i<n;i++)
{
if (arr1[i]%2 == 0)
{
arr2[j] = arr1[i];
j++;
}
else
{
arr3[k] = arr1[i];
k++;
}
}
Code :
using System;
public class Exercise12
{
public static void Main()
{
Console.WriteLine("Abhay");
int n, i, j, tmp;
Code :
using System;
public class Exercise15
{
public static void Main()
{
Console.WriteLine("Abhay");
int i,pos,n;
int[] arr1 = new int[50];
i=0;
while(i!=pos-1)
i++;
while(i<n){
arr1[i]=arr1[i+1];
i++;
}
n--;
Console.Write("\nThe new list is : ");
for(i=0;i<n;i++)
{
Console.Write(" {0}",arr1[i]);
}
Console.Write("\n\n");
}
}
10. Write a C# Sharp program for adding two matrices of the same size.
Code :
using System;
public class Exercise19
{
public static void Main()
{
Console.WriteLine("Abhay");
int i,j,n;
int[,] arr1 = new int[50,50];
int[,] brr1 = new int[50,50];
int[,] crr1 = new int[50,50];
Console.Write("Input the size of the square matrix (less than 5): ");
n = Convert.ToInt32(Console.ReadLine());
for(i=0;i<n;i++)
for(j=0;j<n;j++)
crr1[i,j]=arr1[i,j]+brr1[i,j];
Console.Write("\nThe Addition of two matrix is : \n");
for(i=0;i<n;i++){
Console.Write("\n");
for(j=0;j<n;j++)
Console.Write("{0}\t",crr1[i,j]);
}
Console.Write("\n\n");
}
}