Practical Assignment No 1 to 9 | C Sharp (Programming Language) | Parameter (Computer Programming)

Practical Assignment No.

1
1) Write a program to read two strings from keyboard using the readline statement and display them on one line using two write statements ?? Ans Using System; Class String; { public static void main() { String s1="" , s2=""; s1 = Console.ReadLine(); s2 = Console.ReadLine(); Console.write(s1); Console.write(s2); } } 2) Write a program that assigns two double type value to two variables. Compute their sum,assigns the result to a 3rd variable & display all the 3 values in one line of output ? Using System; Class example { static void main() { double a,b,c; Console.writeline("Enter the number"); a = Double.Parse(Console.ReadLine()); b = Double.Parse(Console.ReadLine()); c = a + b; Console.writeLine("Sum is "+a" "+b+"is"+c); } } 3) Write a progrma to display following pattern * * * * *

*

* * *

* * *

*

Using System; Class example { public static void main() { int i,j,k,s=10,b=1; for (i=1;i<=5;i++) { for(k=1;k<=5;k++) { rad = Double.Parse(Console.ReadLine()); { Console.Write(""); for(j=1;j<=b;j++) { Console.write("*"); } if(i<3) { s=s-2; b=b+2; } else {s=s+2; b=b-2; } Console.WriteLine(); } } 4) Find area of circle ? Using System; Class Area { double rad,ar; static void main() { Console.Writeline("Enter radius"); rad = Double.Parse(Console.ReadLine()); ar = 3.142 * rad * rad Console.Writeline("Area is" + ar); }

} Accept the values for five subjects & print their total & average using command line argument? Using system; Class example { Static void main(String args[]) { int m1,m2,m3,m4,m5,tot; double avg; m1 = int.parse(args[0]); m2 = int.parse(args[0]); m3 = int.parse(args[0]); m4 = int.parse(args[0]); m5 = int.parse(args[0]); tot = m1+m2+m3+m4+m5; avg = tot/5; Console.writeLine( Average is +avg); Console.writeLine( Total is +avg); } } 6.Print the details of the employees using command line arguments ? Using System; Class example { Static void main(String[] ar) String name= , add= ; int sal ,age; name = ar[0]; age = int.Parse(ar[1]); add.ar[2]; sal = int.Parse(ar[4]); Console.writeLine( Employee Details ); Console.writeLine( Name is +name+ age +age+ } }

+ Address +add+ salary +sal);

Write a program to calculate the area of rectangle using command line argument ?

Using system; Class example { Public static void main(String[] ar) { int len,wild; Double ar; len = int.Parse(ar[0]); wid = int.Parse(ar[1]); ar = len*wid; Console.writeline( Area= +ar); } 5) Write a program that takes the line of text John F Kennedy as a command line input & display the following output Kennedy John F ? Using System; Class PGR { String s1,s2,s3; s1= ar[0]; s2=ar[1]; s3=ar[2]; Console.write(s3); Console.write(s1); Console.write(s2); } } 6) Define the two classes one with a method to display the string C sharp & the other to display the string Programming . Write a program using these classes to display a single line output as follows C# programming. Using system; Class A { String s1 = C Sharp ; Public void display() { Console.write(s1); } } Class B

Console.Parse(ar[i]). } } Class C { Public static void main() { A a1 = new A(). s=s+2.s=0. b=b-2.write(s2).writeline(). } } 7) Write a program to print any 10 number & their addition using command line ? Using System. i++) { a = int.{ String s2 = Programming .display()+b1. Public void display() { Console. B b1 = new B(). i<=10 .display()).writeLine(a1. for (int i=1 . } Console. Class example { Public static void main(String[] ar) { int a. } } .

WriteLine( The result of division by zero in C# is: {0} . Solu: using System. If the output is an error message then correct the error & execute the program. Console. int n=200.WriteLine( l= +l). long l=min. class checknum { public static void Main() { double zero=0. long l=min.WriteLine( l= ). Console. Console. } } .Practical Assignment 2 1) WAP to implement the following: int m=100.(0/zero)). class A { public static void Main() { int m=100. 2) What is the output of the following program. int n=200. Solu: using System. } } O/P: l=300.

1. Solu: using System. class DataType Sample { public static void Main() { Console. 4) WAP to compare & display the average of the number. Hexadecimal Literal:{0} . Prog: using Sysytem.WriteLine( Console. Integer Literal:{0} . int num3=int.WriteLine( } } Output: Integer Literal: 58 Double Literal: 1. Double Literal:{0} .6180339887498 Exponential Notation for Decimal Literal: 6.Output: The result of division by zero in C# 3) What is the output of the given program.6023E23F).023E+23 Hexadecimal Literal: 58.61803398134565). class Average { public static void Main(string[] args) { int num1=int.WriteLine( Average: +avg).0x003A). Exponential Notation Decimal Literal:{0} .Parse(arg[2]). } } .58). double avg=(num1+num2+num3)/3. int num2=int. Console.WriteLine( Console.Parse(arg[0]).WriteLine( Console.Parse(arg[1]).

} } . class Temp { public static void Main() { Console. double ft=double.WriteLine( Enter the temperature: ). double ct=(ft-32)1. Console. Console.5) WAP to read the price of an item in decimal form & print the output in paise.Parse(Console.8 Solu: using System. Console.WriteLine( Enter the amount in rupees: ). paise.WriteLine( The temperature in Celsius: +ct). Solu: using Sysytem. rs=double. class A { public static void Main() { double rs.ReadLine()). paise=rs*100. } } 6) WAP to convert the given temperature in Fahrenheit to Celsius using the foll.WriteLine( Paise= +paise).ReadLine()).8. conversion formula: C=(F-32)/1.Parse(Console.

} } } 2) Print the pattern : *** ** *** code using system.write("*").r<=3. class prog1 { public static void main() { for(int r=1.writeline().c++) { console.c<=r.Practical Assignment No 3 1) Print the pattern : * ** *** code using system. } console. class prog2 { public static void main() { .r++) { for(int c=1.

} } } .r--) { for(int c=1.writeline(). for(int j=1. } } } } 3) Print the pattern : *** ** * code using system. console.writeline(). k--.j<=k. for(int i=3.c<=r.r>=1.writeline("*").i>=1.c++) { console. } console.j++) { console.int k=3. class prog3 { public static void main() { for(int r=3.write("*").i--) { if(i==1) k=3.

} } } 5) Print the pattern : * *** ***** code using system.spc--) console. console. for(int i=1. spc--.i++) { if(if==2) spc=1.write(" ").write("*").spc<=spc.j<=jc.i<=3. jc+=2.spc=1. class prog4 { public static void main() { int j<=1. class prog5 . else { for(int spc=1.4) Print the pattern : * *** * code using system. for(int j=1.j++) console.writeline(). } if(jc>3) j<=i.

writeline().r<=5.c++) { console.n code using system.c<=r.c<=r. n=int.. for(int r=1. class prog6 { public static void main() { int n. } } } . } console.c++) { console.. for(r=1.r=r+2) { for(c=1. a++.r++) { for(int c=1.write(a).a=1.{ public static void main() { int r. } console. } } } Print the pattern : 1 23 456 .writeline("*").r<=n.parse(args[0]).c.writeline("/n").

i++) { for(j=o.c<=r.i<=3. for(i= 0. class prog8 { int i.r>=1.c++) { console.r--) { for(int c=1.write("#").j. } } } Print the pattern : 1 01 101 0101 code using system.writeline(). } console.j<=i. class prog7 { public static void main() { for(int r=3.Print the pattern : ### ## # code using system.j++) { if(j==i||i==j+2) .

write(b+" "). } } console. } } } 9) Print the pattern : (pascals triangle) 1 121 1331 14641 code using system. } else b=b*(i-j+1)/j. class prog9 { int i.i++) { for(j=o. console.write(b+" "). } else { console.j.write("1").j<=i. } } .j++) { if(j==0||i==0) { console.write("0"). for(i= 0.i<5.{ console.writeline().

writeline(s. while(len>0) { console.length.len)).console.writeline().substring(0. len--. class prog10 { public static void main() { string s="Mumbai". } } } Print the pattern : Mumbai Mumba Mumb Mum Mu M code using system. } } } . int len=s.

k<=i. A] 1 22 333 4444 55555 Using system. for (i=1. k . j. class B { public static void Main () { int i. } } } B] $ $ $ $ $ $$$$ $$$ $$ $ using system.Write (i+ ). i<6. i<=5 .Writeline (). for (i=1. } Console. .Write ( ).i++) { Console. k++) { Console.j<=i . i++) { for (j=1.j. i++) { for (k=1. class A { public static void main (string []ar) { int i.Practical No 4 1) Write a program to print following outputs using FOR loop.

WriteLine (). } Console. } for (j=1. k>=i.} for(j=5. j<=i. i++) { for (k=num. j++) { Console. j>=i. j. i<=num.Write ( ).Write (). } } } C] 2 1 2 3 3 3 4 4 4 4 5 5 5 5 5 using System. num=5. class C public static void Main () { int i. k--) { Console. for (i=1. k.Write ( =i) } Console. } } } .Write ( $ ). j--) { Console.

class E { public static void Main () { int no. } else { .Parse (console. num = num / 10. Solution using System. if (no = 0) { for (i=no.Write ( Factorial = + fact ).Write ( Enter an integer No ). Console. { fact = fact * I. Console. while (num>0) { rem = num % 10.2) Write a program using While loop to reverse the digit. num=int. i--).Write ( Enter a number to find its factorial ). rem. class D { public static void Main () { int num.i. } } } 3) Write a program that compute table of factorial of numbers. } Console. fact=1.Parse (console. no = int. i>=1. Solution using System. Console.Readline()).readline()).Write (num).

} } Console.Parse (console. num = temp. } else { { counter = counter + 1. { rem = num % 10 sum = sum + rem. Solution using System. } } 4) Write a program to compute the sum of digits of a given integer of a number.WriteLine( You entered 0. for (i = 0. temp.Write ( Enter an integer number ). not valid ). i++).Writeline ( Sum = + sum). } Console. num = int. class E { public static void Main () { int num. } Console. i<=counter. num = num / 10. .Readline (). temp = num. sum = 0. rem = 0.Console. num = num / 10. while(num>0) { rem = num % 10. i. if (num<=10) { break.Writeline ( Number of digits are = + (counter + 1)). counter = 0. Console. rem.Readline()).

s = 1. class F { public static void Main () { int f = 1. . Console. count = 0. no = int.Readline ().Console. } } 5) Wap to print Fibonacci series.Writeline ( *** Investment Equation *** ). float r = 0.1F. n.Write ( +t). class G { public static void Main () { int P = 1000. t.Write ( Enter the numbers ). } 6) Wap to evaluate the following investment equation. } while ((count + 3) < = no). do { t = t + s. t = s.Readline()). Console. Solution using System. Console. count = count + 1. no. V = P (l + r) Solution using System.Write ( Fibonacci series: t++ +s). double V.Parse (console. s = t. Console.

current = float.current.parse (Console.Console.Readline (). } } 7) Wap that accepts five values in US dollars. No of Yrs (n) .Writeline ( Principle (P) . r = r + 0. Solution Using System. y = P * (1 + r). Console. n<= 10. } Console.Parse (Console.Writeline ( ). Console. + n. + r. Rate (R) . Console.Write ( Enter value +i+ in Dollars ). for (i = 1. { Console. V = P * (1 + r). one at a time and convert each value entered o Indian rupees. dol = float. Console.Readline()). rs = dol * current. +v ) P = p + 1000. } } . int I.Writeline ( ). class H { public static void Main () { float dol .Writeline ( + p. i<=5.rs . { Console. n + 1). Value of Money (V) \n ). for (n = 1.Write ( what is current value of $ as per Indian rupees : ).Readline()).01F. i++).Writeline (dol + $ = + rs + Rs ).

I. from 0-20 & adding nos.i<=20.WriteLine( Total no. } if(x==0) { sumeven=sumeven+I. totalno7=0. divisible by 7= +totalno7). } } Console. } } x=0. from 100-200.i++) { x=i%7. Console.: +sumodd). from 100-200. sumodd=0. divisible by 7 between 100200. class J { public static void Main(string[] agrs) { int x=0. if(x==0) { sumdiv7=sumdiv7+i. divisible by 7= +sumdiv7).WriteLine( Sum of all no.: +sumeven). for(i=100.Practical Assignment 5 1) WAP to add odd & even nos.i<=200. Solu: using System. if(x!=0) { sumodd=sumodd+I. Console. for(i=0.WriteLine( Sum of all odd nos.WriteLine( Sum of all even nos.i++) { x=i%2. . sumdiv7=0. Console. sumeven=0. totalno7=totalno7+i.

Write( Enter the value of c: ). d=float.c.WriteLine( ).d. double x1. Console.Console.n.Parse(Console.Parse(Console. Console. Console.ReadLine().Parse(Console. Console. if(response==0) { goto Exit. Console.ReadLine()).temp. a=float. class K { public static void Main(string[] args) { int response.WriteLine( Do you want to enter new value(1 For yes/ 0 For no)? ). } else { goto EnterNewValueAgain.Parse(Console. EnterNewValueAgain: Console.Write( Enter the value of d: ).Parse(Console. b=float. } } . float a.ReadLine()).WriteLine( The denominator equals to 0 cannot proceed further ).ReadLine()).b. if(temp==0) { Console. Solu: using System.Write( Enter the value of a: ).ReadLine()).WriteLine( ). temp=a*d-b*c. Response=int.x2.Write( Enter the value of b: ). c=float. } } 2) WAP to find solution of linear equation.ReadLine()).m. Console.

if(response==0) { goto Exit. . Solu: using System. } } Exit: Console.5 f.79.WriteLine( Value of x2= +x2).46.28. c) in the range of 41 to 80.Parse(Console.Parse(Console.68.25. class M { public static void Main() { int i. d) in the range of 0 to 40.WriteLine( Enter the value of m: ). x1=((m*d)+(b*n))/((a*d)-(c*b)).WriteLine( ).8 f. m=float. Console.ReadLine()). x2=((n*a)+(m*c))/((a*d)-(c*b)). float[] marks={57. Console. b) in the range of 61 to 80.5 f.56.48.ReadLine(). n=float. } } 3) WAP for list of marks ranging from 0 to 100.35. } else { goto EnterNewValueAgain.8 f. Console.25.4 f.49.91.Parse(Console.count80=0.67. Console.else { Console. Console.55.5 f.WriteLine( Enter the value of n: ).9f.01f.46.84).WriteLine( Value of x1= +x1).ReadLine()).98. response=int.19.45.76.97.55. count0=0.59.82.36.ReadLine()). a) in the range of 81 to 100. count40=0.80.85.5f.67.WriteLine( Do you want to enter new values(1 For yes/0 For no)? ).35. count60=0.78.

Solu: using System. >=200 e. b. marks in mathematics >=60. Console.writeline( enter the marks in maths : ).WriteLine( Students in range of 81-100: +count80).WriteLine( Students in range of 61-80: +count60). } } 4) Admission to a professional course. mksphysics. mkschemistry. Console. } Console. Float mathsphysics.i++) { if(marks[i]>80 && marks[i]<101) { count80=count80+1. } else if(marks[i]>60 && marks[i]<81) { count60=count60+1. Console. total in maths and physics >=150. marks in physics >=50 c. total in all 3 sub. mkstotal. marks in chemistry >=40 d.i<=29.for(i=0. } else { count0=count0+1.WriteLine( Students in range of 0-40: +count0). .WriteLine( Students in range of 41-60: +count40). Console. a. } else if(marks[i]>40 && marks[i]<61) { count40=count40+1. class N { public static void Main() { { Float mksmaths.

For (i=1. mathsphysics=(float) (mksmaths +mksphysics).parse(console. k=13. if(cmksmaths>=60 &&mksphysics)=50 && mkschemistry>=40)|| (mkstotal>200 || (mksmaths+mksphysics)>=150)) { Console. Mksphysics=float.readline() ).parse (console. Mkschemistry=float. Consle.readline() ). j. i++) { For (j=1. mksTotal=(float)(mksMaths+mkschemistry+mksphysics). K++.readline() ). .write( enter the marks in physics ). k=1. } Else { console.Mksmaths=float. } } } 5) WAP to print Floyd s triangle Using system. } Console.writeline ( Congratulations!!! The candidate is selected ).write (k+ ).write( enter the marks in chemistry ). Class o { Public static void main () { Int i.writeline( sorry ). j++) { Console.writeline(). Console. } } } 6) A cloth showroom Using system.parse(console. j<i+1.

Console.You need to pay a sum of +discountAmt + instead of of pay a sum of + amt + .0f. If(amt>=0 && amt<+100) { Mill_disc=amt<=100) { Mil_disc=amt*0. Float mill_disc. discountedAMt=amt (mill_disc + Hand_disc).1F Console.=(7. Hand_disc=amt*0. \n thus making a profit of + (Mill_disc + Hand_disc) + Rs.writeline (\n You are eligible to receive a discount of: \n + (amt mill_disc) + Rs. ).5%) on hanloom items.writeline ( \n \n You made a purchase of: + amt + Rs.\n thus making a profit of + (milldisc + handdisc) + Rs.writeline( \n you are eligible to receive a discount of \n +( amt mill_disct rs.=(10%) on handloom items ).Class seasonaldiscount { Public static void Main () { Int amt. ). } Else if ( amt>=101 && amt <=200) { Mill_disc=amt*0. . ).(0%) on mill cloth & \n +(amt hand_disc + Rs.parse(console.(5%) on handloaam items. Amt= int. Hnad_disc=amt*0.writeline( \n you made a purchase of . = (7. Console.\n thus making a profit of of +(mill_disc +hand_disc) + Rs.You need to pay a sum of + DiscountAmt + instead of +. +amt + Rs.write( enter the purchase amount : ). discountedAmt.writeline( \n After all the discounts you need to pay a sum of +discountAmt + instead of +amt + . Else if (amt >+201 && amt<=300) { Mill_disc=amt*0.writeline( \n You ar eligible to recive a discount of : \n + (amt_mill_disc) + Rs. Console.readline() ). ). ). Console. .05f. Console. Console. Hand_disc=amt* 0.05f.writeline( \n All the discount . = (5%) on mill cloth & \n + (amt-hand_disc) + RS.75F. DiscountedAmt=amt (mill_disc +hand-disc Console. Console. DiscountAmt=amt (mill_disc +hand_disc). ).dhand_disc.5%) On mill cloth & \n +(amt-mill_disc) + Rs.writeline( \n After all Discounts . console. ).75F.writeline( \n You made a purchased : +amt + Rs.

} } } 7) WAP that will read the value of X and evaluate following Y= {1 for x>0 {0 for x=0 {-1 for x<0 Using a nested If statement Using system. Console. DiscountedAmt=amt-(mill_disc+hand_disc). If (x>0) { console. Console.=(15%) on handloom items ). ). X=int.writeline( Changing values of Y by nested If ).writeline( \n You made a purchase of: + amt+ ). = (10%) on Mill cloth &\n + (amt+disc)+ Rs. } Console.writeline( \n You are eligible to receive a discount of \n + (amt-mill_disc) + Rs.} Else If (amt>300) { Mill_disc=am*0. . Console.15F Console.writeline( \n after all the discounts you need to pay a sum of +DiscountAmt + instead of +amt + .write ( Eneter the Value of x : ).writeline ( ). Console. Console. Console.writeline ( y+1 ).(console.writeline( Changing values of Y by Else If statements ). \n thus making a profit of + (mill_disc +hand_disc) + Rs.1F.parse. Hand_disc=amt*0. Class changing values of Y { Public static void Main () { Int x.wrieline (y=0 ). y. } } Else { Console.readline() ).writeline( ).

writeline( ). } Else If (x>0) { Console.write( ). Console.If (x == 0) { Console. Console.writeline ( y=1 ). Console.writeline( Y=0 ).writeline ( changing values of Y by Conditional operator ). Y+(x! =0)? ((X>0)? 1: -1): 0. } } .writeline( Y= +Y).readline (). } Console. Console.writeline(y+-1 ). } Else { Console.

a=int. Console. Console. c=int.Write( Enter No. 2: ). 3: ). 6 1) WAP to find maximum and minimum of 3 numbers entered. } else { Largest=b } } If (a<c) { Smallest=a. Console.c .ReadLine()).parse(Console.ReadLine()).largest. } else { largest=c.ReadLine()).Practical Assignment No. } } else { If (c>b) { Largest=c.smallest. 1: ).Write( Enter No. . Class LS { Public static void man() { Int a. if (a>b) { If (a>c) { Largest=a.parse(Console. Using System.b.Write( Enter No.parse(Console. b=int.

interest rate.out int m). } Else { Smallest=b.: +Smallest). int y.Writeline( Largest No. .out int p) { P=x*y.Readline().20. } Public static void Main() { Product(10. } } 3) Write a method that would calculate the value of money for a given period of years abd print the result giving the following details on one line of output. WAP to test its working.WriteLine( Product is: + m). Using System. } } Console. Console. Console. period as input and does not return any value. Class ProductCal { static void Product(int x.: +Largest).Writeline( Smallest No. } } Else { If(c<b) { Smallest=c. Console.} Else { Smallest=c. } } 2) Write a void type method that takes two int type value parameters and one int type out parameter and return the product of two value parameters through the output parameter. The method takes principle amt.

Class Money { public static void Main() { Double r.ReadLine()).i<=n.i++) { V=p*(i+r). Console. For(int i=1.Solution: Using System.Parse(Console.ReadLine()). Console. } Console. Int p=int.Write( Enter the interest rate ). v. Console.Parse(Console.Parse(Console.ReadLine()).WriteLine( Final value= +v). } } .Write( Enter the principle amount ). N=int. r=double.Write( Enter the year ).

For (k=0. Int [] C=new int[length]. If (i<4) { I++.150}. Int i=0.k<=(i+j). { If (A[i]<=B[j]) { C[k]=A[i]. console.length). Using System. Console. Console.510}. 7 1) WAP to merge one-dimentional arrays into a single sorted array that contains every items from array A & B.} } For (i=0. } } Else { c[k]=b[j].write(C[k]+ ).k++).157. in ascending order. Int [] B={275.k.157.550.750.write(c[k]= ).Writeline ( Sorted array list: ).writeline (c[i]+ ).255.I<length.i++) { Console.length+B.240. Int length=(A. Class SA { Public static void main() { Int [] A={127. if (j<4) { J++.Practical Assignment No. } } } } .j=0.

Using System. n. i< user. Char a= a .Add (args[1]). For(int i=0.Add (args[2]). Class AL { Public static void main (String []args) { Arraylist n=new Arraylist().length. Int c=0. n. Using System Collections. C=convert.3) WAP that counts a number of occurances of a particular character in a line of text. } } } 3) WAP that counts the number of words in a text document. User Console. n. } } If (c>a) { Console. i++) { If (user[i]==a) { C#. n. .Add (args[3]).Readline(). Class Prog { Public static void main() { Strinf user. Using System.Writeline ( Enter a Character to check ).c).Add (args[0]).Writeline ( Enter a String ). Console.tochar(console. Console.Writeline ( The character {0} has {1} occourances a.Readline()).

Readline(). S=Console. Using System. } } 5) WAP that reads the name INDIRA GANDHI into two separate string object and then concatenate them into a new string using a) + operater. .count.ReadLine(). s.Replace( .text.Write( Enter any 3 Strings ). Class string { public static void Main() { String s= .n.Writeline( The items before sorting: ). i++) { Console. i<n.WriteLine( The new string is +s). } } 4) WAP that reads a line of text containing three words and then replace all the blank space with an underscore(_) Solution: Using System. Console. Class string { public static void Main() { String s1=new StringBuilder( INDIRA )._). For (int i=0.Add (args[4]).Writeline(i+ : + n[i]). b) Append method Solution: Using System. Console. Console. } Console.

S3=s1. String s3=s1+s2.WriteLine( +s3).Appened( s2 ). Console. } } . Console.WriteLine( +s3).String s2=new StringBuilder( GANDHI ).

Add(args[1]).ReadLine(). using System. class ArrayList { public static void Main(string []args) { ArrayList n = new ArrayList (). for (int i =0. i++) { Console.Collections. n. Console.Count. using System.Count.Add(args[2]). } n.WriteLine ("The items in the Array List before sorting are : "). n. n.Sort(). n. } Console.WriteLine ("The items in the Array List after sorting are : "). for (int i =0. } } Output: The items in the Array List before sorting are : Rajawnt Karan Girish Zeenat Daljit The items in the Array List before sorting are : Daljit Girish Karan Rajawnt Zeenat .Add(args[4]). i++) { Console.Write (i + " : " +n[i]).Add(args[3]).Write (i + " : " +n[i]).Add(args[0]).PRACTICAL ASSIGNMENT 8 1) Read array and sort . i< n. Console. n. i< n.

using System. // Saving the array in another array } for (int i = 0.Length . foreach (int i in arr) { Console.Write(" "+i).Write("The reversed array now has : "). string [] k. public class ReverseArray { public string Reverse(params string [] arr) { string [] j. a ++) { k[a] = j[a].Length]. i < j. i++) { j[i] = k[k.Length . // Here we are reversing the array elements k.2) Reversing array by creating a method reverse . } } } .Length --. // Save all the contents in the array 'j' i++.Write(" "+j). a < j. foreach (int i in j) { Console. } for (int a = 0. Console. } Console. j = new string[i]. // Print the elements of the array 'j' i++.Write("The array list without reversing is : ").

using System.ReadLine().3) Counting number of words in a string .Add(args[2]). Console.Add(args[0]). n.Split(null). n.Write("Enter the string : ").WriteLine("The total number of words in the entered string : "+i). int i = words. Console.Add(args[1]). class CountWords { public static void Main() { string s = "".Length.Collections. s = Console. } } Output: Enter the string : Daljit is making programs The total number of words in the entered string : 4 4) Accepting a list of 5 items . n. . n.ReadLine(). using System. class ShoppingList { public static void Main(string []args) { ArrayList n = new ArrayList (). Console.Add(args[3]). string [] words = s. using System.

n. i< nCount. } } Output: The items in the Shopping List are : Karan Girish Neha Gaurav Raju The items in the Shopping List After modifying are : Karan Girish Raju Daljit End .ReadLine().Sort().Add(5) = "End".Add(3) = "Daljit".WriteLine ("The items in the Shopping List After modifying are : ").n. n.WriteLine((i+1) + " " +n[i]). for (int i =0. for (int i =0.WriteLine(). i< nCount.WriteLine((i+1) + " " +n[i]). } Console. } Console.Remove(2). i++) { Console. Console.WriteLine ("The items in the Shopping List are : ").Add(args[4]). n. n. i++) { Console. Console.

Write (C[k] + " ").240.k. Console.255. using System.Length).510}. Console. } } } for(i=0.550.j=0. int [] B={275.150}. for(k=0.i++) { .Length +B. int CLength=(A. Console.PRACTICAL ASSIGNMENT 9 1) SORTING 2 ARRAYS AND MERGING INTO 1. } } else { C[k]=B[j].750. if(i<4) { i++.157. class SortArray { public static void Main() { int [] A={127.Write (C[k] + " "). if(j<4) { j++.Writeline ( Sorted array list : ). int [] C=new int[CLength].i<CLength.157.k<=(i+j).k++) { if(A[i]<=B[j]) { C[k]=A[i]. int i=0.

} Console.Write(" " + i).WriteLine("Enter the element " + i).Console. using System. Console. } } Output: Sorted array list : 127 150 157 157 240 255 275 510 550 750 2) Finding largest array element and average of array elements via methods. Console. Average = Avg(array1). double Average. Largest = Large(array1).i++) { Console. i>c .WriteLine (). class ArrayFunction { public static void Main() { long Largest. for (int i=0 . .Parse(Console.WriteLine ("\n The largest element in the array is " + Largest). } foreach (int i in array1) { Console.ReadLine().ReadLine()). array1=new int[c]. int c. Console. } Console. c=int.Write("Enter the number of Elements in an Array : ").ReadLine()).WriteLine ("The Average of elements in the array is " +Average). array1[i]=num.Write(C[i] + " "). num=int. int num. int[] array1.Parse(Console.

for ( int i = 0. for ( int i = 0. } sum = sum/arr. i < arr. } } return(temp). i < arr.8 .Console. i++) { sum = sum + arr[i]. } static int Large (params int [] arr) { int temp=0. } static double Avg (params int [] arr) { double sum=0.Length.Length. i++) { if (temp <= arr[i]) { temp = arr[i].Length. } } Output: Enter the number of Elements in an Array : 5 Enter the element 1 : 5 Enter the element 2 : 7 Enter the element 3 : 3 Enter the element 4 : 1 Enter the element 5 : 8 largest element in the array is 8 The Average of elements in the array is 4. return(sum).ReadLine().

a = int.Parse(Console.Write("Enter No 1 : ").Parse(Console.ReadLine()). if (a > b) { if(a > c) { largest = a. } } else { if(c>b) { largest = c.ReadLine()). } } if (a < b) { if(a < c) { smallest = a.3) Finding the max and min of 3 numbers . c = int. using System. class LargestSmallest { public static void Main() { int a. b = int.ReadLine()).smallest.largest.c.Write("Enter No 2 : "). Console. Console.b. } .Parse(Console. Console. } else { largest = c. } else { largest = b.Write("Enter No 3 : ").

double deviation. } else { smallest = b. using System.2.23}.ReadLine(). int n = nos. } } Console. Console.57.0F.WriteLine("\n\n The Largest Number = " +largest).14.5F. mean.Length. Console.24.74. } } Output: Enter No 1 : 15 Enter No 2 : 54 Enter No 3 : 21 The Largest Number = 54 The Smallest Number = 15 4) Calculate standard deviation and mean of the array elements.sumofsq = 0.Write("Array List consists of : ").95.23.else { smallest = c. } } else { if(c<b) { smallest = c.WriteLine("\n The Smallest Number = " +smallest).6. class StdDeviation { public static void Main() { float [] nos = {3. . float sum = 0.0F. Console.

WriteLine("\n Mean = " +mean).Write(nos[i] + " "). } for (int i = 0.15 Deviation = 49. Console.ReadLine().WriteLine("\n\n Sum = " +sum). } mean = sum / n. i ++) { Console. Console. deviation = Math. } } Output: Array List consists of : 3.for (int i = 0. i ++) { sum = sum + nos[i]. i < n. i ++) { sumofsq = sumofsq + (nos[i]*nos[i]). i < n.0).WriteLine("\n Deviation = " +deviation ).Sqrt(sumofsq / 8. i < n.5 Mean = 32. Console.5381797202 . } for (int i = 0. Console.5 57 2 6 24 14 95 23 74 23 Sum = 321.

Sign up to vote on this title
UsefulNot useful