zadanie_8
unknown
plain_text
2 years ago
3.0 kB
4
Indexable
using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; namespace zadanie8 { internal class Program { static double[,] Ilorazy(int[] t1, int[] t2) { double[,] outTab = new double[t1.Length, t2.Length]; double x = 0, y = 0; for (int i = 0; i < t1.Length; i++) { x = t1[i]; for(int j = 0; j < t2.Length; j++) { y = t2[j]; if(y == 0.0) throw new Exception("Dzielenie przez zero NIEEEE"); else outTab[i, j] = x/y; } } return outTab; } static void Main(string[] args) { /* * Napisz metodę Ilorazy, przyjmującą w parametrach dwie tablice typu int t1 i t2, * zwracającą tablicę dwuwymiarową(regularną) której elementy są równe odpowiednim * ilorazom elementów tablic podanych w parametrach, tzn. t[i, j] = t1[i] / t2[j]. * W przypadku, dzielenia przez 0 należy zgłosić wyjątek.W metodzie Main należy * zastosować blok try catch w celu obsługi wyjątku. */ /* Console.WriteLine("Podaj rozmiar tablic: "); int n = Convert.ToInt32(Console.ReadLine()); Random r = new Random(); int[] tab1 = new int[n]; int[] tab2 = new int[n]; // wypelnienie tablic (wartościami od -100 do 100) for (int i = 0; i < tab1.Length; i++) tab1[i] = r.Next(-100, 100); for (int i = 0; i < tab2.Length; i++) tab2[i] = r.Next(-100, 100); */ int[] tab1 = new int[] {0, 6, 9}; int[] tab2 = new int[] {1, 0, 3}; Console.WriteLine("\n=========tab 1============"); foreach (int i in tab1) Console.Write(i+ " "); Console.WriteLine("\n=========tab 2============"); foreach (int i in tab2) Console.Write(i + " "); Console.WriteLine(); Console.WriteLine(); try { double[,] result = Ilorazy(tab1, tab2); for (int i = 0; i < result.GetLength(0); i++) { for (int j = 0; j < result.GetLength(1); j++) { Console.Write(result[i, j] + " "); } Console.WriteLine(); } } catch (Exception e) { Console.WriteLine("BLAD TO: " + e.Message); } Console.ReadKey(); } } }
Editor is loading...