Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lab Practical File of "Dot Net Lab" Subject Code-CSP0503 (P)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 33

Lab Practical File of

"DOT NET LAB"


Subject Code- CSP0503[P]

Submitted by

B.Tech(CSE)

Submitted to
Asst. Prof. Rahul Yadav

Department of CSE

School of Engineering & Technology

ITM UNIVERSITY GWALIOR, (M.P.), INDIA

INDEX
S.No Title Page No
1. Write a C# Sharp program to print on screen the output of adding, subtracting, 2
multiplying and dividing of two numbers which will be entered by the user.

2. Write a C# Sharp Program to check number is whether EVEN or ODD without 4


using any arithmetic or relational operators.
3. Write a C# Sharp program that takes a number as input and print its 6
multiplication table.
4. Write a C# program and compute the sum of the digits of an integer. 8

5. Write a program in C# Sharp to display the number in reverse order. 9

6. Write a program in C# Sharp to check whether a number is a palindrome or not. 10

7. Write a C# Sharp program to check whether a given number is an Armstrong 12


number or not.

8. Write a program in C# Sharp to create a function to swap the values of two 14


integer numbers.

9. Write a program in C# Sharp to create a function to calculate the area & 16


Perimeter of a Rectangle.

10. Find the sum of all the elements present in a jagged array of 3 inner arrays. 18

11. Write a program in C# Sharp to separate odd and even integers in separate 21
arrays.

12. Write a program in C# Sharp to read an array and remove the duplicate 25
elements from it.

13. 26
Write a C# Program to print Number Triangle.
14. Write a C# Program Store and Display Employee Information. 28
15. Write a Program in C# using Internal Access Specifier. 30

1
1.Write a C# Sharp program to print on screen the output of adding, subtracting, multiplying and
dividing of two numbers which will be entered by the user.

using System;

public class Program1

public static void Main(string[] args)

int input1, input2;

float sum, subtract, multiplication, division;

Console.Write("Enter the First Number(positive natural number):" + "\n");

input1 = int.Parse(Console.ReadLine());

Console.Write("Enter the Second Number:(positive natural number)" + "\n");

input2 = int.Parse(Console.ReadLine());

sum = input1 + input2;

subtract = input1 - input2;

multiplication = input1 * input2;

division = input1 / input2; // divides first number by second number

Console.Write("Number1 = " + input1 + "\n");

Console.Write("Number2 = " + input2 + "\n");

Console.Write("Sum = " + sum + "\n");

Console.Write("Subtraction = " + subtract + "\n");

2
Console.Write("Multiplication= " + multiplication + "\n");

Console.Write("Division (first no / second no) = " + division + "\n");

Console.ReadKey();

}}

3
2. Write a C# Sharp Program to check number is whether EVEN or ODD without using any arithmetic
or relational operators.

using System;

public class Program2

public static void Main(string[] args)

int input1;

Console.Write("Enter the Number(whole number):" + "\n");

input1 = int.Parse(Console.ReadLine());

if ((input1 & 1)==1)

Console.Write("The Number is ODD " + "\n");

else

Console.Write("The Number is Even " + "\n");

Console.ReadKey();

}}

4
5
6
3. Write a C# Sharp program that takes a number as input and print its multiplication table.

using System;

public class Program3

public static void Main(string[] args)

int i, num;

//Reading number

Console.WriteLine("Enter number to print table: ");

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

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

//Printing table of number entered by user

Console.Write("{0} X {1} = {2} \n", num, i, num * i);

Console.ReadKey();

7
8
4. Write a C# program and compute the sum of the digits of an integer.

using System;

public class Program4

public static void Main(string[] args)

int n, sum = 0, m;

Console.Write("Enter a number: ");

n = int.Parse(Console.ReadLine());

while (n > 0)

m = n % 10;

sum = sum + m;

n = n / 10;

Console.Write("Sum is= " + sum);

Console.ReadKey();

9
5. Write a program in C# Sharp to display the number in reverse order.

using System;

public class Program5

public static void Main(string[] args)

int n, reverse = 0, rem;

Console.Write("Enter a number: ");

n = int.Parse(Console.ReadLine());

while (n != 0)

rem = n % 10;

reverse = reverse * 10 + rem;

n /= 10;

Console.Write("Reversed Number: " + reverse);

Console.Read();

}}

10
6. Write a program in C# Sharp to check whether a number is a palindrome or not.

using System;

public class Program6

public static void Main(string[] args)

int n, r, sum = 0, temp;

Console.Write("Enter the Number: ");

n = int.Parse(Console.ReadLine());

temp = n;

while (n > 0)

r = n % 10;

sum = (sum * 10) + r;

n = n / 10;

if (temp == sum)

Console.Write("Number is Palindrome.");

else

Console.Write("Number is not Palindrome");

Console.ReadKey();

11
12
7.Write a C# Sharp program to check whether a given number is an Armstrong number or not.

using System;

public class Program7

public static void Main(string[] args)

int n, r, sum = 0, temp;

Console.Write("Enter the Number= ");

n = int.Parse(Console.ReadLine());

temp = n;

while (n > 0)

r = n % 10;

sum = sum + (r * r * r);

n = n / 10;

if (temp == sum)

Console.Write("Armstrong Number.");

else

Console.Write("Not Armstrong Number.");

Console.Read();

13
14
8.Write a program in C# Sharp to create a function to swap the values of two integer numbers.

using System;

public class Program8

public static void Main(string[] args)

int number1, number2, temp;

void swap(int x, int y)

temp = x;

x = y;

y = temp;

number1 = x;

number2 = y;

Console.Write("Enter the number X: ");

number1 = int.Parse(Console.ReadLine());

Console.Write("The value of X is : {0} ",number1 + "\n");

Console.Write("Enter the number Y: ");

number2 = int.Parse(Console.ReadLine());

Console.Write("The value of Y is {0} : ",number2 + "\n");

swap(number1, number2);

Console.Write("The swaped values are X={0} and Y={1} " ,number1,number2 + "\n");

Console.ReadKey(); }}

15
16
9. Write a program in C# Sharp to create a function to calculate the area & Perimeter of a Rectangle.

using System;

public class Program9

public static double Area_Rectangle(double x, double y)

double AOR;

AOR = x * y;

return (AOR);

public static double Perimeter_Rectangle(double x, double y)

double POR;

POR = 2 * (x + y);

return POR;

public static void Main(string[] args)

double length, breadth, area, perimeter;

Console.Write("Enter the length of the rectangle: ");

length = Convert.ToDouble(Console.ReadLine());

Console.Write("Enter the breadth of the rectangle: ");

breadth = Convert.ToDouble(Console.ReadLine());

area = Area_Rectangle(length, breadth);

perimeter = Perimeter_Rectangle(length, breadth);

17
Console.Write("The rectangle area={0} and perimeter={1}", area,perimeter+"\n");

Console.ReadKey();

18
10. Find the sum of all the elements present in a jagged array of 3 inner arrays.

using System;

class JaggedArrays

int[][] jagged = new int[3][];

public void ReadArrays()

Console.Write("\n Enter the size of First inner array: ");

jagged[0] = new int[int.Parse(Console.ReadLine())];

Console.WriteLine("\n Enter the elements of First inner array: ");

for (int i = 0; i < jagged[0].Length; i++)

jagged[0][i] = int.Parse(Console.ReadLine());

Console.Write("\n Enter the size of Second inner array: ");

jagged[1] = new int[int.Parse(Console.ReadLine())];

Console.WriteLine("\n Enter the elements of Second inner array: ");

for (int i = 0; i < jagged[1].Length; i++)

jagged[1][i] = int.Parse(Console.ReadLine());

Console.Write("\n Enter the size of Third inner array: ");

jagged[2] = new int[int.Parse(Console.ReadLine())];

Console.WriteLine("\n Enter the elements of Third inner array: ");

for (int i = 0; i < jagged[2].Length; i++)

jagged[2][i] = int.Parse(Console.ReadLine());

public void FindSum()

19
int sum = 0;

for (int i = 0; i < jagged[0].Length; i++)

sum = sum + jagged[0][i];

for (int i = 0; i < jagged[1].Length; i++)

sum = sum + jagged[1][i];

for (int i = 0; i < jagged[2].Length; i++)

sum = sum + jagged[2][i];

Console.WriteLine("\n\n\n Sum of all the three inner arrays is = {0}", sum);

public void PrintArrays()

Console.Write("\n\n Elements of First inner array: ");

for (int i = 0; i < jagged[0].Length; i++)

Console.Write(jagged[0][i] + "\t");

Console.Write("\n\n Elements of Second inner array: ");

for (int i = 0; i < jagged[1].Length; i++)

Console.Write(jagged[1][i] + "\t");

Console.Write("\n\n Elements of Third inner array: ");

for (int i = 0; i < jagged[2].Length; i++)

Console.Write(jagged[2][i] + "\t");

public class Program10

public static void Main(string[] args)

20
{

JaggedArrays JA = new JaggedArrays();

JA.ReadArrays();

JA.PrintArrays();

JA.FindSum();

Console.ReadLine();

21
11. Write a program in C# Sharp to separate odd and even integers in separate arrays.

using System;

public class Program11

public static void Main(string[] args)

int[] arr1 = new int[10];

int[] arr2 = new int[10];

int[] arr3 = new int[10];

int i, j = 0, k = 0, n;

Console.Write("\n\nSeparate odd and even integers in separate arrays:\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());

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

if (arr1[i] % 2 == 0)

arr2[j] = arr1[i];

22
j++;

else

arr3[k] = arr1[i];

k++;

Console.Write("\nThe Even elements are : \n");

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

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

Console.Write("\nThe Odd elements are :\n");

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

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

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

Console.ReadKey();

23
24
12.Write a program in C# Sharp to read an array and remove the duplicate elements from it.

using System;

using System.Linq;

public class Program12

public static void Main(string[] args)

int n,flag;

int[] intArray;

Console.Write("Please Enter the length of the array: ");

n = int.Parse(Console.ReadLine());

intArray = new int[n];

Console.Write("Please Enter the elements of the array ");

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

intArray[i]= int.Parse(Console.ReadLine());

Console.Write("The elements of array without dublication are ");

int[] intArray_updated = intArray.Distinct().ToArray();

foreach(int items in intArray_updated)

Console.Write(items + " ");

Console.ReadKey();

}}

25
26
13. Write a C# Program to print Number Triangle.

using System;

public class shashidatt_program_13

public static void Main(string[] args)

int i, j, k, l, n;

Console.Write("Enter the Range=");

n = int.Parse(Console.ReadLine());

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

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

Console.Write(" ");

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

Console.Write(k);

for (l = i - 1; l >= 1; l--)

Console.Write(l);

Console.Write("\n");

27
}

Console.ReadKey();

28
14. Write a C# Program Store and Display Employee Information.

using System;

public class Employee

public int id;

public String name;

public float salary;

public void insert(int i, String n, float s)

id = i;

name = n;

salary = s;

public void display()

Console.WriteLine(id + " " + name + " " + salary);

class shashidatt_program14

public static void Main(string[] args)

Employee e1 = new Employee();

Employee e2 = new Employee();

e1.insert(101, "Sumit ", 890000f);

29
e2.insert(102, "shashi datt", 490000f);

e1.display();

e2.display();

Console.ReadKey();

30
15. Write a Program in C# using Internal Access Specifier.

using System;

namespace AccessSpecifiers

class InternalTest

internal string name = "Shashi Datt";

internal void Msg(string msg)

Console.WriteLine("Hello " + msg);

class Shashidatt_program_15

static void Main(string[] args)

InternalTest internalTest = new InternalTest();

// Accessing internal variable

Console.WriteLine("Hello " + internalTest.name);

// Accessing internal function

internalTest.Msg("Btech.cse");

Console.ReadKey();

31
32

You might also like