04. Sum of Two Numbers C#
Здравейте!
Относно задачата от лекцията за мафическото число - очевидно нещо с break-a не сработва както трябва
https://pastebin.com/P6rKgzuV
Може ли малко помощ..?
Здравейте!
Относно задачата от лекцията за мафическото число - очевидно нещо с break-a не сработва както трябва
https://pastebin.com/P6rKgzuV
Може ли малко помощ..?
не съм използвал break, защото и при мен не става, но можем да прекратим цикъла ако променим числата във for-а :)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp109
{
class Program
{
static void Main(string[] args)
{
int num1 = int.Parse(Console.ReadLine());
int finish = int.Parse(Console.ReadLine());
int magical = int.Parse(Console.ReadLine());
int counter = 0;
bool yes = true;
for (int i = num1; i <= finish; i++)
{
for (int x = num1; x <= finish; x++)
{
counter++;
if (i + x == magical)
{
Console.WriteLine($"Combination N:{counter} ({i} + {x} = {magical})");
yes = false;
i = finish;
}
}
}
if (yes)
{
Console.WriteLine($"{counter} combinations - neither equals {magical}");
}
Console.ReadLine();
}
}
}