Проверить истинность высказывания - C# (182920)
Формулировка задачи:
Точки с координатами (x1, y1), (x2, y2), (x3, y3) лежат в первой или третьей координатной четверти
как это можно сократить
static void Main(string[] args)
{
Console.Write("ввод x1:");
int x1 = Convert.ToInt32(Console.ReadLine());
Console.Write("ввод y1:");
int y1 = Convert.ToInt32(Console.ReadLine());
Console.Write("ввод x2:");
int x2 = Convert.ToInt32(Console.ReadLine());
Console.Write("ввод y2:");
int y2 = Convert.ToInt32(Console.ReadLine());
Console.Write("ввод x3:");
int x3 = Convert.ToInt32(Console.ReadLine());
Console.Write("ввод y3:");
int y3 = Convert.ToInt32(Console.ReadLine());
bool l = (x1 > 0 & x2 > 0 & x3 > 0) && (y1 > 0 & y2 > 0 & y3 > 0)|| (x1 < 0 & x2 < 0 & x3 < 0) && (y1 < 0 & y2 < 0 & y3 < 0);
Console.WriteLine(l);
}Решение задачи: «Проверить истинность высказывания»
textual
Листинг программы
using System;
namespace _1or3
{
class Program
{
static void Main(string[] args)
{
Console.Write("ввод x1:");
int x1 = Convert.ToInt32(Console.ReadLine());
Console.Write("ввод y1:");
int y1 = Convert.ToInt32(Console.ReadLine());
Console.Write("ввод x2:");
int x2 = Convert.ToInt32(Console.ReadLine());
Console.Write("ввод y2:");
int y2 = Convert.ToInt32(Console.ReadLine());
Console.Write("ввод x3:");
int x3 = Convert.ToInt32(Console.ReadLine());
Console.Write("ввод y3:");
int y3 = Convert.ToInt32(Console.ReadLine());
//в первой четверти x и y всегда больше 0, их произведение тоже
//в третьей x и y всегда меньше 0, а их произведение > 0
//отсюда такое решение
bool l = (x1 * y1 > 0 & x2 * y2 > 0 & x3 * y3 > 0);
Console.WriteLine(l);
Console.ReadLine();
}
}
}