Вы находитесь на странице: 1из 3

Zadatak 1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Domaci3
{
class Program
{
static void Main(string[] args)
{
int n;
Console.WriteLine("Koliko trouglova ima");
n = int.Parse(Console.ReadLine());
Trougao[] t = new Trougao[n];
int i, j;
double a, b, c;
for (i = 0; i < n; i++)
{
Console.WriteLine("Unesi stranice "+(i+1)+" trougla");
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
c = int.Parse(Console.ReadLine());
t[i] = new Trougao(a, b, c);
if (t[i].Moze() == false)
{
Console.WriteLine("Ne moze da bude trougao");
i--;
}
}
for (i = 0; i < n - 1; i++)
for (j = 0; j < n - i - 1; j++)
if (t[j].Povrsina() > t[j + 1].Povrsina())
{
Trougao temp = t[j];
t[j] = t[j + 1];
t[j + 1] = temp;
}
Console.WriteLine("Uredjeni niz: ");
for (i = 0; i < n; i++)
{
t[i].Ispis();
Console.WriteLine("P je " + Math.Round(t[i].Povrsina(), 2));
}
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Domaci3
{
class Trougao
{
private double a;
private double b;
private double c;
public double A
{
get
{
return this.a;
}
set
{
this.a = value;
}
}
public double B
{
get
{
return this.b;
}
set
{
this.b = value;
}
}
public double C
{
get
{
return this.c;
}
set
{
this.c = value;
}
}
public Trougao()
{
a = 1;
b = 1;
c = 1;
}
public Trougao(double a, double b, double c)
{
this.a = a;
this.b = b;
this.c = c;
}
public bool Moze()
{
if (a + b > c && a + c > b && b + c > a)
{
return true;
}
else
{
return false;
}
}
public double Obim()
{
return a + b + c;
}
public double Povrsina()
{
double s = Obim() / 2;
return Math.Sqrt(s * (s - a) * (s - b) * (s - c));
}
public void Ispis()
{
Console.Write("Trougao: " + a + " " + b + " " + c);
}

}
}

Вам также может понравиться