Practical 11
Write a program in C# to create a function to calculate the area
and parameter of a ractangle.
using System;
namespace calcurectangular
{
class Program
{
static void Main(string[] args)
{
int a,p,l,w;
Console.WriteLine("Enter the length of regtangle");
l = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the width of regtangle");
w = int.Parse(Console.ReadLine());
p = 2*(l+w);
a = w * l;
Console.WriteLine("Parameter of rectangle :"+p);
Console.WriteLine("Area of rectangle :" + a);
Console.ReadLine();
}
}
}
Output:-
Practical 12
Write a program in C# to find the sum of all the elements present
in a jagged array of 3 inner arrays.
class Program
{
static void Main(string[] args)
{
int[][] jag = new int[3][];
jag[0] = new int[2];
jag[1] = new int[2];
jag[2] = new int[2];
int[] sum = new int[3];
int result = 0;
int i, j;
for (i = 0; i < 3; i++)
{
sum[i] = 0;
}
for (i = 0; i <jag.Length; i++)
{
Console.WriteLine("Enter the values off array " + (i + 1) + " jag:");
for (j = 0; j < jag[i].Length; j++)
{
jag[i][j] = int.Parse(Console.ReadLine());
}
}
for (i = 0; i <jag.Length; i++)
{
for (j = 0; j < jag[i].Length; j++)
{
sum[i] = sum[i] + jag[i][j];
}
}
for (i = 0; i < 3; i++)
result = result + sum[i];
Console.WriteLine("The result of individual jags row-wise: ");
for (i = 0; i < 3; i++)
Console.Write(sum[i] + "\t");
Console.WriteLine();
Console.WriteLine("The final sum of all the elements in the jagged
array:"+result);
Console.Read();
}
}
(BCAN1CA18030) Dot NET Framework (CSL0662)
Practical 13
Write a program in C# to separate odd and even integers in separate
arrays.
using System;
namespace oddeven
{
class Program
{
static void Main(string[] args)
{
{
int[] no = new int[6] ;
Console.WriteLine("Enter any 6 Numbers");
for (int l = 0; l < 6; l++)
{
no[l] = int.Parse(Console.ReadLine());
}
int[] E= new int[10];
int[] O = new int[10];
int i, j = 0, k = 0;
for (i = 0; i < 6; i++ {
if (no[i] % 2 == 0)
{
E[j] = no[i];
j++;
}
else
{
O[k] = no[i];
k++;
}
}
Console.WriteLine("Even numbers...");
for (i = 0; i < j; i++)
{
Console.WriteLine(E[i]);
}
Console.WriteLine("Odd numbers...");
for (is
= 0; i < k; i++)
{
Console.WriteLine(O[i]);
}
Console.ReadLine();
(BCAN1CA18030) Dot NET Framework (CSL0662)
Practical 14
Write a program in C# to read an array and remove the duplicate elements
from it.
class Program
{
static void Main(string[] args)
{
int n, count = 0, c, d;
int[] a = new int[100];
int[] b = new int[100];
Console.WriteLine("Enter number of elements in array\n");
n = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Enter "+n+" integers\n");
for (c = 0; c < n; c++)
a[c] = Convert.ToInt16(Console.ReadLine());
for (c = 0; c < n; c++)
{
for (d = 0; d < count; d++)
{
if(a[c] == b[d])
break;
}
if (d == count)
{
b[count] = a[c];
count++;
}
}
Console.WriteLine("Array obtained after removing duplicate elements:\n");
for (c = 0; c < count; c++)
{
Console.WriteLine(b[c]);
}
Console.ReadKey();
}
}
}
Output:-
(BCAN1CA18030) Dot NET Framework (CSL0662)
Practical 15
Write a program in C# to read and print student’s information
using two classes.
using System;
namespace twoclss
{
class Program
{
static void Main(string[] args)
{
Teacher d = new Teacher();
d.Teach();
Student s = new Student();
s.Learn();
s.Teach();
Console.ReadKey();
}
class Teacher
{
public void Teach()
{
Console.WriteLine("Teach");
}
}
class Student : Teacher
{
public void Learn()
{
Console.WriteLine("Learn");
}
}
}
}
Output:-
(BCAN1CA18030) Dot NET Framework (CSL0662)
Practical 18
Write a program in C# to read and print employee information with
department and information using hierarchical inheritance.
class Program
{
static void Main(string[] args)
{
{
Principal g = new Principal();
g.Monitor();
Teacher d = new Teacher();
d.Monitor();
d.Teach();
Student s = new Student();
s.Monitor();
s.Learn();
Console.ReadKey();
}
}
class Principal
{
public void Monitor()
{
Console.WriteLine("Monitor");
}
}
class Teacher : Principal
{
public void Teach()
{
Console.WriteLine("Teach");
}
}
class Student : Principal
{
public void Learn()
{
Console.WriteLine("Learn");
}
}
Output:-
(BCAN1CA18030) Dot NET Framework (CSL0662)