You are on page 1of 21

prg 2 using using using using using System; System.Collections.Generic; System.Linq; System.Text; System.Threading.

Tasks;

namespace Program_2 { class Program { static void Main(string[] args) { int i, sum=0, largest; int [] array = new int[10]; Console.WriteLine("Enter 10 numbers..\n "); for (i = 0; i < 10; i++) { Console.Write("Enter element " + (i +1) + " : "); array[i] = int.Parse(Console.ReadLi ne()); } largest = array[0]; for (i = 0; i < 10; i++) { sum = sum + array[i]; if (array[i] > largest) largest = array[i];

} Console.WriteLine("\nLargest number is : " + largest); Console.WriteLine("\nSum of all numbers is : " + sum); Console.ReadLine(); } } } ---------------------------------------------------------------------------------------------------------prg 3 using using using using using System; System.Collections.Generic; System.Linq; System.Text; System.Threading.Tasks;

namespace Program_3 { class Program { public static void Main(string[] args) { string[] str; int choice, size; char rep = 'y'; Console.Write("Enter the number of stud ent names : "); size = int.Parse(Console.ReadLine()); str = new string[size]; for (int i = 0; i < size; i++) { Console.Write("Enter student name " + (i+1));

str[i] = Console.ReadLine(); } while (rep == 'y' || rep == 'Y') { Console.Clear(); Console.WriteLine("1 -> Sort"); Console.WriteLine("2 -> Reverse"); Console.WriteLine("3 -> Clear"); Console.WriteLine("4 -> Exit"); Console.Write("Choose your operatio n.."); choice = int.Parse(Console.ReadLine ()); switch (choice) { case 1 : Array.Sort(str); display(size, str); break; case 2 : Array.Reverse(str); display(size, str); break; case 3 : Array.Clear(str, 0, str.Len gth); Console.WriteLine("Student names are cleared now.."); break; case 4 : Environment.Exit(0); break; } Console.Write("\nDo you want to con tinue ? (Y / y)"); rep = char.Parse(Console.ReadLine() );

} } public void display(int size, string[] str) { int i; for (i = 0; i < size; i++) { Console.WriteLine("\t" + str[i]); } } } } -------------------------------------------------------------------------------------------------------prg 4 using using using using using System; System.Collections.Generic; System.Linq; System.Text; System.Threading.Tasks;

namespace Program_4 { class Program { static void Main(string[] args) { int i, j; int [,] arr1 = new int[2,2]; int[,] arr2 = new int[2, 2]; Console.WriteLine("Enter the values for first matrix..\n"); for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { Console.Write("Enter value for

Row : " + i + " and Column : " + j + " : "); arr1[i, j] = int.Parse(Console. ReadLine()); } } Console.WriteLine("\n\nEnter the values for second matrix..\n"); for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { Console.Write("Enter value for Row : " + i + " and Column : " + j + " : "); arr2[i, j] = int.Parse(Console. ReadLine()); } } Console.WriteLine("\n\nThe sum of two m atrices is : \n"); for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { Console.Write("\t" + (arr1[i, j ] + arr2[i, j])); } Console.WriteLine("\n"); } Console.ReadLine(); } } } -------------------------------------------------------------------------------------------------------------------------prg 5 using System;

using using using using

System.Collections.Generic; System.Linq; System.Text; System.Threading.Tasks;

namespace Program_5 { class Program { static void Main(string[] args) { int i, j, rows; Console.Write("Enter the number of arra ys.. "); rows = int.Parse(Console.ReadLine()); int[][] j_array = new int[rows][]; Console.WriteLine(); Console.Write("Enter the number of elem ents for each array..\n"); for (i = 0; i < rows; i++) { Console.Write("Enter element for Ar ray [" + (i+1) +"] : "); j_array[i] = new int[int.Parse(Cons ole.ReadLine())]; } Console.WriteLine("\nEnter the values for each element in Jagged Array : \n"); for (i = 0; i <= j_array.GetUpperBound( 0); i++) { for (j = 0; j <= j_array[i].GetUppe rBound(0); j++) { Console.Write("Enter value for Jagged Array [" + i + "][" + j + "] : ");

j_array[i][j] = int.Parse(Conso le.ReadLine()); } Console.WriteLine(); } Console.WriteLine("\nThe populated Jagg ed Array is like this : \n"); for (i = 0; i <= j_array.GetUpperBound( 0); i++) { for (j = 0; j <= j_array[i].GetUppe rBound(0); j++) { Console.Write("\t" + j_array[i] [j]); } Console.WriteLine("\n"); } Console.ReadLine(); } } } -------------------------------------------------------------------------------------------------------------------prg 6 using using using using using System; System.Collections.Generic; System.Linq; System.Text; System.Threading.Tasks;

namespace Program_6 { class student

{ int roll_no; string s_name; string stream; public void get_data(int i) { Console.WriteLine(); Console.Write("Enter Student [" + i + " ] Roll No : "); roll_no = int.Parse(Console.ReadLine()) ; Console.Write("Enter Student [" + i + " ] Name : "); s_name = Console.ReadLine(); Console.Write("Enter Student [" + i + " ] Stream : "); stream = Console.ReadLine(); } public void display() { Console.WriteLine("\t" + roll_no + "\t\ t" + s_name + "\t\t" + stream); } } class Program { static void Main(string[] args) { Console.Write("Enter No. of Students : "); student[] std = new student[int.Parse(C onsole.ReadLine())]; for (int i = 0; i <= std.GetUpperBound( 0); i++) { std[i] = new student(); std[i].get_data(i); }

Console.WriteLine(); Console.WriteLine("\t" + "Roll No" + "\ t\t" + "Name" + "\t\t" + "Stream"); Console.WriteLine("\t" + "-------" + "\ t\t" + "----" + "\t\t" + "------"); for (int i = 0; i <= std.GetUpperBound( 0); i++) { std[i].display(); } Console.ReadLine(); } } } ----------------------------------------------------------------------------------------------------------------prg 7 using using using using using using System; System.Collections.Generic; System.Linq; System.Text; System.Threading.Tasks; System.Diagnostics;

namespace Program_7 { class bank_acc { public string name; public int acc_no; public string acc_type; public int amt; public void assign_values(string name1, int acc_no1, string acc_type1, int amt1) { name = name1; acc_no = acc_no1;

acc_type = acc_type1; amt = amt1; } public void deposite_amt(int dep_amt) { amt = amt + dep_amt; } public void withdraw_amt(int with_amt) { if (with_amt > amt) Console.WriteLine("Sorry, not suffi cient balance in account.."); else amt = amt - with_amt; } public void display(int i) { Console.WriteLine(); Console.WriteLine("Acc. ID : \t\t" + (i +1)); Console.WriteLine("Name : \t\t" + name) ; Console.WriteLine("Type : \t\t" + acc_t ype); Console.WriteLine("Amount : \t" + amt); } } class Program { static void Main(string[] args) { bank_acc[] acc = new bank_acc[3]; int choice; char rep = 'y'; for (int i = 0; i < 3; i++) {

acc[i] = new bank_acc(); Console.Write("Enter Name : "); string name = Console.ReadLine(); Console.Write("Enter Acc. Type : ") ; string acc_type = Console.ReadLine( ); Console.Write("Enter Amount : "); int amt = int.Parse(Console.ReadLin e()); Console.WriteLine(); acc[i].assign_values(name, i + 1, a cc_type, amt); } while (rep == 'y' || rep == 'Y') { Console.Clear(); for (int i = 0; i < 3; i++) { acc[i].display(i); } Console.WriteLine(); Console.WriteLine("1.Deposite Amoun t"); Console.WriteLine("2.Withdraw Amoun t"); Console.WriteLine("3.Display Info") ; Console.WriteLine("4.Exit"); Console.WriteLine(); Console.Write("Choose Operation : " ); choice = int.Parse(Console.ReadLine ()); switch (choice) { case 1: Console.WriteLine(); Console.Write("Enter accoun

t no. : "); int tmp = int.Parse(Console .ReadLine()); Console.Write("Enter Amount : "); int amt = int.Parse(Console .ReadLine()); acc[tmp - 1].deposite_amt(a mt); break; case 2: Console.Write("Enter Acc. I D : "); int tmp2 = int.Parse(Consol e.ReadLine()); Console.Write("Enter Amount : "); int amt2 = int.Parse(Consol e.ReadLine()); acc[tmp2 - 1].withdraw_amt( amt2); break; case 3: Console.Write("Enter accoun t no. : "); int tmp3 = int.Parse(Consol e.ReadLine()); acc[tmp3 - 1].display(tmp3) ; break; case 4: Environment.Exit(0); break; default: Console.WriteLine("Invalid choice.."); break; } Console.Write("Perform another oper ation ? (Y / N) : "); rep = char.Parse(Console.ReadLine() );

} } } } ----------------------------------------------------------------------------------------------------------prg 8 using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace Prac_8 { class Sample { static int c=0; public Sample() { c++; } public static void dispC() { Console.WriteLine(c); } } class Program { static void Main(string[] args) { Sample s1 = new Sample(); Sample s2 = new Sample(); Sample s3 = new Sample(); Sample s4 = new Sample(); Sample.dispC(); Console.ReadKey(); } } }

================================================== ================================================== =============== pro 9 using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace ConsoleApplication2 { class vector { int[] a = new int[5]; public void create_vector() { Console.WriteLine("Enter elements for v ector...."); for (int i = 0; i < 5; i++) { a[i] = int.Parse(Console.ReadLine() ); } } public void modify() { int ele, pos; Console.Write("\n\nEnter new element to replace:"); ele = int.Parse(Console.ReadLine()); Console.Write("Enter Position at which you want to replace element:"); pos = int.Parse(Console.ReadLine()); a[pos - 1] = ele; Console.WriteLine("Element is replaced successfully..."); }

public void mul_scalar() { int s; Console.Write("\n\nEnter scalar value:" ); s = int.Parse(Console.ReadLine()); for (int i = 0; i < 5; i++) { a[i] = a[i] * s; } } public void display() { Console.WriteLine("\n\nVector Elements are...."); for (int i = 0; i < 5; i++) { if (i == 4) Console.Write(a[i]); else Console.Write(a[i] + ", "); } } } class Program { static void Main(string[] args) { vector v = new vector(); v.create_vector(); v.display(); v.modify(); v.display(); v.mul_scalar(); v.display(); Console.Read(); } }

} -----------------------------------------------------------------------------------------------------prg 10 using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace ConsoleApplication1 { class xyz { public void power(int a, int b) { Console.WriteLine("Answer(Integer)=" + Math.Pow(a, b)); } public void power(float a, float b) { Console.WriteLine("Answer(Float)=" + Ma th.Pow(a, b)); } } class Program { static void Main(string[] args) { int m, n; float p, q; xyz x = new xyz(); Console.WriteLine("Enter two integer nu mbers..."); Console.Write("Number1:");

m = int.Parse(Console.ReadLine()); Console.Write("Number1:"); n = int.Parse(Console.ReadLine()); x.power(m, n); Console.WriteLine("Enter two float numb ers..."); Console.Write("Number1:"); p = float.Parse(Console.ReadLine()); Console.Write("Number1:"); q = float.Parse(Console.ReadLine()); x.power(p,q); Console.ReadLine(); } } } ----------------------------------------------------------------------------------------------------------prg 11 using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace ConsoleApplication1 { class person { protected string name; protected int age; } class student:person { int rno;

string c; public void Get_Data() { Console.Write("Enter Roll No:"); rno = int.Parse(Console.ReadLine()); Console.Write("Enter class:"); c = Console.ReadLine(); Console.Write("Enter Name:"); name = Console.ReadLine(); Console.Write("Enter Age:"); age = int.Parse(Console.ReadLine()); } public void display() { Console.WriteLine(rno + "\t" + c + "\t" + name + "\t" + age); } } class Program { static void Main(string[] args) { student[] s; int n; Console.Write("\n\nHow many Students:") ; n = int.Parse(Console.ReadLine()); s = new student[n]; for (int i = 0; i < n; i++) { s[i] = new student(); Console.WriteLine("\n\nStudent--" + (i + 1)); s[i].Get_Data(); }

Console.WriteLine("\n\n\nRollNo\tClass\ tName\tAge"); Console.WriteLine("==================== ==================================="); for (int i = 0; i < n; i++) { s[i].display(); } Console.ReadLine(); } } } -----------------------------------------------------------------------------------------------------------------prg 13 using using using using System; System.Collections.Generic; System.Linq; System.Text;

namespace ConsoleApplication1 { class student { protected int rno; protected string name; } public interface exam { void get_data(); void res(); } class result : student, exam

{ int m1, m2, m3; public void get_data() { Console.Write("\n 8enter Roll no:-"); rno = int.Parse(Console.ReadLine()); Console.Write("enter Name:-"); name=Console.ReadLine(); Console.Write("enter marks 1:-"); m1 =int.Parse(Console.ReadLine()); Console.Write("enter marks 2:-"); m2 = int.Parse(Console.ReadLine()); Console.Write("enter marks 3:-"); m3 = int.Parse(Console.ReadLine()); } public void res() { int total; float per; total = m1 + m2 + m3; per = total / 3; Console.Write(rno + "\t" + name + "\t" + m1 + "\t" + m2 + "\t" + m3 + "\t" + total + "\t " + per); } } class Program { static void Main(string[] args) { int n; result [] r; Console.Write("how many student are ent er:-");

n = int.Parse(Console.ReadLine()); r = new result[n]; for (int i = 0; i < n; i++) { r[i] = new result(); Console.Write("student information " + (i + 1)); r[i].get_data(); } Console.Write("rollno\tname\tmark1\tmar k2\tmark3\ttotal\tpercentage"); for (int i = 0; i < n; i++) { r[i].res(); } Console.ReadLine(); } } }

You might also like