2023-03-23 21:08:55 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
public class Lab1
|
|
|
|
|
{
|
|
|
|
|
public static void Main(String[] args)
|
|
|
|
|
{
|
|
|
|
|
/*o1 = +
|
|
|
|
|
c3 = 0
|
|
|
|
|
o2 = *
|
|
|
|
|
c7 = short */
|
|
|
|
|
|
2023-04-14 20:07:51 +03:00
|
|
|
|
// 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);
|
2023-03-23 21:08:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-14 20:07:51 +03:00
|
|
|
|
public static void Calculation(int A, int C, int N, short B, int M, bool divisionByZero)
|
2023-03-23 21:08:55 +02:00
|
|
|
|
{
|
2023-04-14 20:07:51 +03:00
|
|
|
|
var s = 0;
|
|
|
|
|
if ((A <= -C && -C <= N) || (B <= 0 && 0 <= M))
|
2023-03-23 21:08:55 +02:00
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Division by zero!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = A; i <= N; i++)
|
|
|
|
|
{
|
2023-04-14 20:07:51 +03:00
|
|
|
|
if (i + C == 0)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Division by zero!");
|
|
|
|
|
divisionByZero = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-03-23 21:08:55 +02:00
|
|
|
|
|
|
|
|
|
for (short j = B; j <= M; j++)
|
|
|
|
|
{
|
|
|
|
|
if (j == 0)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Оскільки j = 0, то сума просто буде 0");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-14 20:07:51 +03:00
|
|
|
|
s += (i * j) / (i + C);
|
2023-03-23 21:08:55 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!divisionByZero)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"s = {s};");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|