Uni.sulicihan.edu.krd



Q 1: Write program that read two array of 2D of size 3*3 and perform 4 arithmetic operation using switch NOTE: bellow only one case continue as same case 2 , case 3 ,case 4 .class Program { static void Main(string[] args)37871402372360 { int[,] a = new int[3, 3]; int[,] b = new int[3, 3]; int[,] c = new int[3, 3]; int i, j,input; Console.WriteLine("enter A"); for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) a[i, j] = int.Parse(Console.ReadLine()); } Console.WriteLine("enter B"); for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) b[i, j] = int.Parse(Console.ReadLine()); } Console.WriteLine("enter input"); input = int.Parse(Console.ReadLine()); switch (input) { case 1: for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { c[i, j] = a[i, j] + b[i, j]; Console.Write(" " + c[i, j]); } } break; default: Console.WriteLine("error"); break; } Console.ReadKey(); } }}Q 2: Write a program that read one array of 1D of size 4 and find the following:1- Summation of the array2-Multiplication of the array 3- Average of the array4- Division of the array NOTE: By using function NOTE: continue 3 and 4 as others Solution:34347151886585class Program { public int i; public int ADD(int[] a) { int sum=0; for (i = 0; i < 4; i++) sum+=a[i]; return(sum); } public int MULTIPLICATION(int[] a) { int mult = 1; for (i = 0; i < 4; i++) mult *= a[i]; return (mult); } static void Main(string[] args) { int[] a = new int[4]; int i; Console.WriteLine("enter A"); for (i = 0; i < 4; i++) a[i] = int.Parse(Console.ReadLine()); Program p = new Program(); Console.WriteLine("additon of array"+ " " + p.ADD(a)); Console.WriteLine("multiplication of array" + " " + p.MULTIPLICATION(a)); Console.ReadKey(); } } }Q3: Write program that read an array of 1D of size 4 then find 1- Reverse of each element 2- Palindrome ----------- > find it by your self 3- Factorial NOTE: you can perform the same but by using switch case ( 3 cases) class Program { public int i,reverse = 0; public void REVERSE(int[] a) { for (i = 0; i < 4; i++) { while (a[i] != 0) { reverse = reverse * 10; reverse = reverse + a[i] % 10; a[i] = a[i] / 10; } Console.Write(" " + reverse); reverse = 0; } } public void factorial(int[] a) { int c, fact = 1; for (i = 0; i < 4; i++) { for (c = 1; c <=a[i]; c++) fact = fact * c; a[i] = fact; Console.Write(" " + a[i]); fact = 1; } } static void Main(string[] args) { int[] a = new int[4]; int i; Console.WriteLine("enter A"); for (i = 0; i < 4; i++) a[i] = int.Parse(Console.ReadLine()); Program p = new Program(); p.REVERSE(a); p.factorial(a); Console.ReadKey(); }}} ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download