udayacsmaterials.files.wordpress.com€¦  · web viewexno: 01 name :. date: reg no:...

40
EXNO: 01 NAME : DATE: REG NO: RA16310050200 WRITE A PROGRAM IN C# TO CHECK WHETHER A NUMBER IS PALINDROME OR NOT. AIM: To write a program in c# to check whether a number is palindrome or not. PROGRAM: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Palindrome { class Program { static void Main(string[] args) { int num,temp; int digit; int reverse = 0; 1

Upload: others

Post on 04-Apr-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

EXNO: 01 NAME :DATE: REG NO: RA16310050200

WRITE A PROGRAM IN C# TO CHECK WHETHER A NUMBER IS PALINDROME OR NOT.

AIM:

To write a program in c# to check whether a number is palindrome or not.

PROGRAM:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Palindrome

{

class Program

{

static void Main(string[] args)

{

int num,temp;

int digit;

int reverse = 0;

Console.WriteLine("Enter a number");

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

temp=num;

1

Page 2: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

while(num!=0)

{

digit = num % 10;

reverse = reverse * 10 + digit;

num=num /= 10;

Console.WriteLine("The reverse of the number is: {0}",reverse);

if (temp == reverse)

{

Console.WriteLine("This number is a palindrome!");

Console.ReadLine();

}

else

{

Console.WriteLine("This number is not a palindrome");

Console.ReadLine();

}

}

}

}

2

Page 3: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

Output:

RESULT:

Thus the program has been completed successfully.

3

Page 4: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

EX NO: 02 NAME :DATE: REG NO: RA16310050200

WRITE A PROGRAM IN C# TO DEMONSTRATE COMMAND LINE ARGUMENTS PROCESSING

AIM:

To write a program in c# to demonstrate command line arguments processing.

PROGRAM:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Commandline1

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("\nNumber of CommadLine Arguments :" + args.Length);

Console.Write("\nCommandline Arguments Are :\t");

for (int i = 0; i<args.Length; i++)

{

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

}

Console.ReadLine();

}}

}4

Page 5: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

Output:

RESULT:

Thus the program has been completed successfully.

5

Page 6: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

EX NO: 03 NAME :DATE : REG NO : RA16310050200

WRITE A PROGRAM IN C# TO FIND THE ROOTS OF QUADRATIC EQUATION.

AIM:

To write a program in c# to find the roots of quadratic equation.

PROGRAM:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Quadratic

{

class Program

{

static void Main(string[] args)

{

float a, b, c;

double disc, deno, x1, x2;

Console.WriteLine("ENTER THE VALUES OFA,B,C...");

a = float.Parse(Console.ReadLine());

b = float.Parse(Console.ReadLine());

c = float.Parse(Console.ReadLine());

if (a == 0)

{

x1 = -c / b;

Console.WriteLine("The roots are Linear:", x1);6

Page 7: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

}

else

{ disc = (b * b) - (4 * a * c);

deno = 2 * a;

if (disc > 0)

{

Console.WriteLine("THE ROOTS ARE REAL AND DISTINCTROOTS");

x1 = (-b / deno) + (Math.Sqrt(disc) / deno);

x2 = (-b / deno) - (Math.Sqrt(disc) / deno);

Console.WriteLine("THE ROOTS ARE... " + x1 + " and " + x2);

}

else if (disc == 0)

{ Console.WriteLine("THE ROOTS ARE REPEATEDROOTS");

x1 = -b / deno;

Console.WriteLine("THE ROOT IS...: " + x1);

}

else

{ Console.WriteLine("THE ROOTS ARE IMAGINARYROOTS\n");

x1 = -b / deno;x2 = ((Math.Sqrt((4 * a * c) - (b * b))) / deno);

Console.WriteLine("THE ROOT 1: " + x1 + "+i" +x2);

Console.WriteLine("THE ROOT 2:" + x1 + "-i" + x2);

}

}

Console.ReadLine();

}}}

7

Page 8: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

Output:

RESULT:

Thus the program has been completed successfully.

8

Page 9: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

EX NO: 04 NAME :DATE : REG NO : RA16310050200

WRITE A PROGRAM IN C# TO DEMONSTRATE BOXING AND UNBOXING.

AIM:

To write a program in c# to demonstrate boxing and unboxing.

PROGRAM:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Boxing

{

class Program

{

static void Main(string[] args)

{

int m = 10;

object a = m; // boxing

try

{

Console.WriteLine("Value of m is:" + a);

object n = 20;

int b = (int)n; // attempt to unbox

Console.WriteLine("Value of n is:" + b);

System.Console.WriteLine("Unboxing OK.");

9

Page 10: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

Console.ReadLine();

}

catch (System.InvalidCastException e)

{

System.Console.WriteLine("Error: Incorrect unboxing." + e.Message);

}

}

}

}

Output:

RESULT:

Thus the program has been completed successfully.

10

Page 11: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

EX NO: 05 NAME :DATE : REG NO : RA16310050200

WRITE A PROGRAM IN C# TO IMPLEMENT STACK OPERATIONS

AIM:

To write a program in c# to implement stack operations.

PROGRAM:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace stack

{

class Program

{

static void Main(string[] args)

{

int top = -1;

int[] s = new int[10];

Console.WriteLine("Enter The Size of TheStack");

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

while (true)

{Console.WriteLine("1.Push");

Console.WriteLine("2.Pop");

Console.WriteLine("3.Display");

Console.WriteLine("4.Exit");

11

Page 12: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

Console.WriteLine("Enter your choice :");

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

switch (ch)

{

case 1:

if (top > MAX - 1)

Console.WriteLine("... Stack Overflow ...");

else

{

Console.WriteLine("Enter the item :");

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

s[++top] = n;

}

break;

case 2:

if (top == -1)

Console.WriteLine(" ... Stack Underflow ...");

else

{

Console.WriteLine("Popped item :" + s[top--]);

}

break;

case 3:

if (top == -1)

Console.WriteLine("... Stack underflow ...");

else {

12

Page 13: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

Console.WriteLine(“Elements in the stack”);

for (inti = top; i>= 0; i--)

Console.WriteLine(s[i]);

}

break;

case 4:

return;

default:

Console.WriteLine("Wrong Choice");

break;

}

}

}

}

}

13

Page 14: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

Output:

RESULT:

Thus the program has been completed successfully.

14

Page 15: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

EX NO: 06 NAME :DATE : REG NO : RA16310050200

WRITE A PROGRAM TO DEMONSTRATE OPERATOR OVERLOADING.

AIM:

To write a program to demonstrate operator overloading.

PROGRAM:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace OperatorOverloading

{

publicstructaddOpp

{

private double a;

publicaddOpp(double a)

{

this.a = a;

}

public override string ToString()

{

return string.Format("{0}", a);

}

15

Page 16: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

static public addOpp operator +(addOpp lhs, addOpprhs)

{

return new addOpp(lhs.a + rhs.a);

}

}

class Program

{

static void Main(string[] args)

{

Console.WriteLine("Enter Two Numbers");

addOpp c1 = new addOpp(double.Parse(Console.ReadLine()));

addOpp c2 = new addOpp(double.Parse(Console.ReadLine()));

addOpp c3 = c1 + c2;

Console.WriteLine("First Value is {0}", c1);

Console.WriteLine("Second Value is {0}", c2);

Console.WriteLine("Addition is {0}", c3);

Console.ReadLine();

}

}

}

16

Page 17: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

Output:

RESULT:

Thus the program has been completed successfully.

17

Page 18: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

EX NO: 07 NAME :DATE : REG NO : RA16310050200

WRITE A PROGRAM IN C# TO FIND THE SECOND LARGEST ELEMENT IN A SINGLE DIMENSIONAL ARRAY.

AIM:

To write a program in c# to find the second largest element in a single dimensional array.

PROGRAM:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Largest

{

class Program

{

static void Main(string[] args)

{

int [] a = new int[10];

int i, j;

Console.WriteLine("Enter the No. of Elements");

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

Console.WriteLine("Enter the Elements");

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

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

}18

Page 19: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

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

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

{

if (a[j] < a[j + 1])

{

int temp = a[j];

a[j] = a[j + 1];

a[j + 1] = temp;

}

}

i = 1;

while (a[i] == a[0])

i++;

if (i>= n)

{

Console.WriteLine("Second Largest Element Does Not Exist");

Console.ReadLine();

}

else

{

Console.WriteLine("Second Largest Element is " +a[i]);

Console.ReadLine();

}

}

}

}19

Page 20: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

Output:

RESULT:

Thus the program has been completed successfully.

20

Page 21: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

EX NO: 08 NAME :DATE : REG NO : RA16310050200

WRITE A PROGRAM IN C# TO MULTIPLY TO MATRICES USING RECTANGULAR ARRAYS

AIM:

To write a program in c# to multiply to matrices using rectangular arrays.

PROGRAM:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Matrixmul

{

classMatrixMultiplication

{

int [,] a;

int [,] b;

int [,] c;

public int m1, n1, m2, n2;

public void ReadMatrix()

{

Console.WriteLine("\n Size of Matrix 1:");

Console.Write("\n Enter the number of rows in Matrix 1:");

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

Console.Write("\n Enter the number of columns in Matrix 1");

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

21

Page 22: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

a = new int[m1, n1];

Console.WriteLine("\n Size of Matrix 2 :");

Console.Write("\n Enter the number of rows in Matrix 2 :");

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

Console.Write("\n Enter the number of columns in Matrix 2");

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

b = new int[m2, n2];

if (n1 != m2)

{

Console.WriteLine("columns of A & Rows of B matrix are not equal");

Console.ReadLine();

Environment.Exit(0);

}

else

{

Console.WriteLine("\n Enter the elements of Matrix 1:");

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

{ for (int j = 0; j < n1; j++)

{ a[i, j] = int.Parse(Console.ReadLine());

} }

Console.WriteLine("\n Enter the elements of Matrix 2:");

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

{

for (int j = 0; j < n2; j++)

{

b[i, j] = int.Parse(Console.ReadLine());

22

Page 23: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

} }

} }

public void PrintMatrix() {

Console.WriteLine("\n Matrix 1:");

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

{

for (int j = 0; j < n1; j++)

{

Console.Write("\t" + a[i, j]);

}

Console.WriteLine();

}

Console.WriteLine("\n Matrix 2:");

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

{

for (int j = 0; j < n2; j++)

{

Console.Write("\t" + b[i, j]);

}

Console.WriteLine();

}

Console.WriteLine("\nResultant Matrix after multiplying:");

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

{ for (int j = 0; j < n2; j++)

{Console.Write("\t" + c[i, j]);

}

23

Page 24: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

Console.WriteLine();

}

Console.ReadLine();

}

public void MultiplyMatrix()

{

c = new int[m1, n2];

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

{

for (int j = 0; j < n2; j++)

{

c[i, j] = 0;

for (int k = 0; k < n1; k++)

c[i, j] = c[i, j] + a[i, k] * b[k, j];

} }

} }

class Program

{

static void Main(string[] args)

{

MatrixMultiplication MM = new MatrixMultiplication();

MM.ReadMatrix();

MM.MultiplyMatrix();

MM.PrintMatrix();

}

}}

24

Page 25: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

Output:

RESULT:

Thus the program has been completed successfully.

25

Page 26: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

EX NO: 09 NAME :DATE : REG NO : RA16310050200

FIND THE SUM OF ALL THE ELEMENTS PRESENT IN A JAGGED ARRAY OF 3 INNER ARRAYS

AIM:

To find the sum of all the elements present in a jagged array of 3 inner arrays.

PROGRAM:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Jaggedarray

{

class Program

{

static void Main(string[] args)

{

int [][] jarr = new int[3][];

int s = 0;

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

{

Console.WriteLine("Enter the Size of the Array" +(i +1));

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

jarr[i] = new int[n];

Console.WriteLine("Enter the Values of Array " +(i + 1));

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

26

Page 27: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

{

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

s = s + jarr[i][j];}

}

n = n + 0;

}

Console.WriteLine("Sum= " + s);

Console.ReadLine();

}

}

}

27

Page 28: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

Output:

RESULT:

Thus the program has been completed successfully.

28

Page 29: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

EX NO: 10 NAME :DATE : REG NO : RA16310050200

WRITE A PROGRAM TO REVERSE A GIVEN STRING USING C#.

AIM:

To write a program to reverse a given string using c#.

PROGRAM:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Reverse

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("Enter the String :");

string a = Console.ReadLine();

intlen = a.Length;

Console.Write("The Reverse of String is :");

for (int i = len - 1; i>= 0; i--)

{

Console.Write(a[i]);

29

Page 30: udayacsmaterials.files.wordpress.com€¦  · Web viewexno: 01 name :. date: reg no: ra16310050200. write a program in c# to check whether a number is palindrome or not

}

Console.WriteLine();

Console.ReadLine();

}

}}

Output:

RESULT:

Thus the program has been completed successfully.

30