syed

16
C# Practical File 2013 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace neha { class MATRIX { static void Main(string[] str) { Console.WriteLine(" Program to calculate addition of two matrix of size 2*2 "); int[,] m1 = new int[3, 3]; Console.WriteLine(); Console.WriteLine("Enter the Values of 1st matrix : "); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { m1[i, j] = int.Parse(Console.ReadLine()); } } int[,] m2 = new int[3, 3]; Console.WriteLine("Enter the Values of 2nd matrix :"); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { m2[i, j] = int.Parse(Console.ReadLine()); } } int[,] c = new int[3, 3]; Console.WriteLine("The Addtion of Matrix is : "); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { Console.Write((m1[i, j] + m2[i, j]) + " "); } Console.WriteLine(); } Console.ReadLine(); } By: Syed Mohd Naqi Zaidi /***WAP to calculate addition of two 2*2

Transcript of syed

Page 1: syed

C# Practical File 2013

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace neha{ class MATRIX { static void Main(string[] str) { Console.WriteLine(" Program to calculate addition of two matrix of size 2*2 "); int[,] m1 = new int[3, 3]; Console.WriteLine(); Console.WriteLine("Enter the Values of 1st matrix : "); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { m1[i, j] = int.Parse(Console.ReadLine()); } }

int[,] m2 = new int[3, 3]; Console.WriteLine("Enter the Values of 2nd matrix :"); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { m2[i, j] = int.Parse(Console.ReadLine()); } }

int[,] c = new int[3, 3]; Console.WriteLine("The Addtion of Matrix is : "); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { Console.Write((m1[i, j] + m2[i, j]) + " "); } Console.WriteLine(); } Console.ReadLine(); } }}

By: Syed Mohd Naqi Zaidi

/***WAP to calculate addition of two 2*2 matrix***/

Page 2: syed

C# Practical File 2013

OUTPUT

By: Syed Mohd Naqi Zaidi

Page 3: syed

C# Practical File 2013

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace NEHA{ class STRING {

public static void length() {

string s; Console.WriteLine("Enter The String "); s = Console.ReadLine(); Console.WriteLine("Lenght of the String is :" + s.Length);

} public static void palindrome() {

string str, revstr; Console.WriteLine("Enter Any String to Know It is Palindrome or not"); str = Console.ReadLine(); char[] tempstr = str.ToCharArray(); Array.Reverse(tempstr); revstr = new string(tempstr); bool caseignore = str.Equals(revstr, StringComparison.OrdinalIgnoreCase); if (caseignore == true) { Console.WriteLine("............" + str + " Is a Palindrome.........."); } else { Console.WriteLine("............" + str + " Is Not a Palindrome........"); } }

static void Main(string[] args) { length(); palindrome(); Console.ReadLine(); } }}

By: Syed Mohd Naqi Zaidi

/*** create a class to perform following operations:-

Calculate the length of string. Check whether the string is a palindrome or not. ***/

Page 4: syed

C# Practical File 2013

OUTPUT

By: Syed Mohd Naqi Zaidi

Page 5: syed

C# Practical File 2013

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace neha{ class EVENODD { static void Main(string[] str) {

Console.WriteLine("Even" + " " + "ODD"); for (int i = 0; i < 50; i++) { if ((i % 2) == 0) Console.Write(i + " "); else { if ((i % 2) != 0) Console.WriteLine(i); } }

Console.ReadLine(); } }}

By: Syed Mohd Naqi Zaidi

/***WAP to generate series of even and odd numbers separately between 1to50***/

Page 6: syed

C# Practical File 2013

OUTPUT

By: Syed Mohd Naqi Zaidi

Page 7: syed

C# Practical File 2013

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace neha{ class FACTORIAL {

public static string rev(string st) { char[] ar = st.ToCharArray(); Array.Reverse(ar); return new string(ar); }

static int a, b = 1; static string st; static void Main(string[] str) { Console.Write(" Program to Calculate the Factorial, length, Reverse of the string "); Console.WriteLine(); Console.WriteLine(); Console.Write("Enter the any value:"); a = int.Parse(Console.ReadLine()); for (int i = a; i > 1; i--) { b = b * i; } Console.Write("Factorial number: "); Console.WriteLine(b); st = b.ToString(); st = rev(st);

Console.Write("Length of string: "); Console.WriteLine(st.Length); Console.Write("Reverse String: "); Console.WriteLine(st);

Console.ReadKey(); } }}

By: Syed Mohd Naqi Zaidi

/***WAP to find the factorial of given integer, inverse of the number, calculate sum of the digits***/

Page 8: syed

C# Practical File 2013

OUTPUT

By: Syed Mohd Naqi Zaidi

Page 9: syed

C# Practical File 2013

Define a class to represent a bank account having following members name, acc. No, type, initial values deposited amt, withdraw amt and display balance.

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text.RegularExpressions;using System.Windows.Forms;using System.Collections;using System.Media;using System.Resources;using System.Reflection;using System.Diagnostics;using System.IO;

namespace timer_and_acount_prog{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } Form2 frm = new Form2(); private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "" || textBox3.Text == "" || (!Regex.IsMatch(textBox1.Text, @"[0-9]") || !(Regex.IsMatch(textBox3.Text, @"[0-9]")))) { MessageBox.Show("Please Enter the integer value in: " + '\n' + '\n' + " ACCOUNT NO. AND TOTAL AMOUNT", "MANI MESSAGE"); } else if (textBox2.Text == "" || textBox4.Text == "" || (!Regex.IsMatch(textBox2.Text, @"[a-zA-Z]") || !(Regex.IsMatch(textBox4.Text, @"[a-zA-Z]")))) { MessageBox.Show("Please Enter the String in: " + Environment.NewLine+'\n' + "NAME AND ACCOUNT TYPE", "MANI MESSAGE"); } else { frm.a = int.Parse(textBox1.Text); frm.b = int.Parse(textBox3.Text); frm.d = button1.Text; frm.Show();

By: Syed Mohd Naqi Zaidi

Page 10: syed

C# Practical File 2013

this.Hide(); }

}

private void button3_Click(object sender, EventArgs e) { if (textBox1.Text == "" || textBox3.Text == "" || (!Regex.IsMatch(textBox1.Text, @"[0-9]") || !(Regex.IsMatch(textBox3.Text, @"[0-9]")))) { MessageBox.Show("Please Enter the integer value in: " + '\n' + '\n' + " ACCOUNT NO. AND TOTAL AMOUNT", "MANI MESSAGE"); } else if (textBox2.Text == "" || textBox4.Text == "" || (!Regex.IsMatch(textBox2.Text, @"[a-zA-Z]") || !(Regex.IsMatch(textBox4.Text, @"[a-zA-Z]")))) { MessageBox.Show("Please Enter the String in: "+ Environment.NewLine+'\n' +"NAME AND ACCOUNT TYPE", "MANI MESSAGE"); } else { frm.a = int.Parse(textBox1.Text); frm.b = int.Parse(textBox3.Text); frm.d = button3.Text; frm.Show(); this.Hide(); }

}

private void Form1_Load(object sender, EventArgs e) { }

private void button4_Click(object sender, EventArgs e) { this.Close(); }

private void button2_Click(object sender, EventArgs e) { MessageBox.Show("Account No.: " + textBox1.Text.ToString() + '\n' + '\n' + "Name Is: " + textBox2.Text + '\n' + '\n' + "Total Amount: " + textBox3.Text.ToString() + '\n' + '\n' + label4.Text + ": " + textBox4.Text, "MANI MESSAGE"); } }}

FORM 2

using System;

By: Syed Mohd Naqi Zaidi

Page 11: syed

C# Practical File 2013

using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text.RegularExpressions;using System.Windows.Forms;

namespace timer_and_acount_prog{ public partial class Form2 : Form { public int a, b, c; public string d,s; public Form2() { InitializeComponent(); }

private void button1_Click(object sender, EventArgs e) { Form1 f = new Form1(); if (textBox5.Text == "" || (!Regex.IsMatch(textBox5.Text,@"[0-9]"))) { MessageBox.Show("Please Enter the integer value"); } else { c = int.Parse(textBox5.Text); if (label5.Text == "Deposit") { textBox2.Text = (b + c).ToString(); } else { if (b > c) { textBox2.Text = (b - c).ToString(); } else MessageBox.Show("Your Amount Is More than total Amount "+'\n'+" Your Current Balance is: "+b); } MessageBox.Show("ACCOUNT NO. " + textBox1.Text + " " + " Balance Is " + textBox2.Text, "KALRA BANK ;) :P"); } } private void Form2_Load(object sender, EventArgs e) { Form1 f = new Form1(); f.Hide(); textBox1.Text = a.ToString(); label5.Text = d; label5.Visible = true; textBox5.Visible = true; textBox1.ReadOnly = true; }

By: Syed Mohd Naqi Zaidi

Page 12: syed

C# Practical File 2013

private void button2_Click(object sender, EventArgs e) { Form1 frm = new Form1(); this.Close(); frm.Show(); }

}}

By: Syed Mohd Naqi Zaidi

Page 13: syed

C# Practical File 2013

OUTPUT:-

By: Syed Mohd Naqi Zaidi

Page 14: syed

C# Practical File 2013

Swap two values using call by reference .

a) Create a method using reference parameter to calculate square of no.

b) Create a class by name decompose that separates the integer no and fractional part of given floating point no.

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace Swap{ class Swapping { class Swap { public void swap(ref int a, ref int b) { int t; t = a; a = b; b = t; }

static void squareRef(ref int refParameter) { refParameter *= refParameter; } public class SwapDemo { public static void Main() { Swap ob = new Swap(); int x = 10, y = 20; Console.WriteLine("X and Y Before call: " + x + " " + y); ob.swap(ref x, ref y); Console.WriteLine("X and Y After call: " + x + " " + y); int arg; arg = 5; squareRef(ref arg); Console.WriteLine("Square Of a Number is :"+arg); Console.Read(); } } } }}

By: Syed Mohd Naqi Zaidi

Page 15: syed

C# Practical File 2013

By: Syed Mohd Naqi Zaidi