From c95a243c84e0a9846ddee0b27d6c5324ba368882 Mon Sep 17 00:00:00 2001 From: idkWhatUserNameToUse Date: Fri, 14 Apr 2023 11:04:57 +0300 Subject: [PATCH] reviwed and fixed lab1 --- lab1_with_extracted_method/Program.cs | 29 +++++++-------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/lab1_with_extracted_method/Program.cs b/lab1_with_extracted_method/Program.cs index 868c0f8..440ae7f 100644 --- a/lab1_with_extracted_method/Program.cs +++ b/lab1_with_extracted_method/Program.cs @@ -8,25 +8,15 @@ public class Lab1 c3 = 0 o2 = * c7 = short */ + - // var A = 4; - // short B = 3; - // var N = 10; - // var M = 10; - // - // var C = 1; - // var s = 0; - // - // bool divisionByZero=false; - - - Calculation(4, 3, 10, 10, 1, false); + calculation(4, 3, 10, 10, 11, false); } - public static void Calculation(int A, int C, int N, short B, int M, bool divisionByZero) + public static void calculation(int A, int C, int N, short B, int M, bool divisionByZero) { - var s = 0; - if ((A <= -C && -C <= N) || (B <= 0 && 0 <= M)) + double s = 0; + if (A <= -C && -C <= N) { Console.WriteLine("Division by zero!"); return; @@ -34,12 +24,7 @@ public class Lab1 for (int i = A; i <= N; i++) { - if (i + C == 0) - { - Console.WriteLine("Division by zero!"); - divisionByZero = true; - break; - } + for (short j = B; j <= M; j++) { @@ -49,7 +34,7 @@ public class Lab1 break; } - s += (i * j) / (i + C); + s +=(double)(i * j) / (i + C); } }