DuongTron - PTB2
using System;
public class DT{
public double BK{
get { return bk; }
set { bk = value; }}
public void cv(){
Console.WriteLine("CV = {0}",2*Math.PI*bk);}
public void dt(){
Console.WriteLine("DT = {0}", Math.PI * bk * bk);}
private double bk;}
public class Tester{
public static void Main(){
DT dt = new DT();
Console.Write("Bk = ");
dt.BK = double.Parse(Console.ReadLine());
dt.cv();
dt.dt();}}
-----
-----
------
using System;
namespace TH_BT_02
{
public class PT
{
public double A
{
get { return a; }
set { a = value; }
}
public double B
{
get { return b; }
set { b = value; }
}
public double C
{
get { return c; }
set { c = value; }
}
public double X1
{
get { return x1; }
set { x1 = value; }
}
public double X2
{
get { return x2; }
set { x2 = value; }
}
public bool pt1(double b, double c)
{
if (b != 0)
{
x1 = -c / b; x2 = -c / b;
return true;
}
else return false;
}
public bool pt2(double a,double b, double c)
{
double del = (b*b) - (4*a*c);
if (del >= 0)
{
x1 = (-b + Math.Sqrt(del)) / (2 * a);
x2 = (-b - Math.Sqrt(del)) / (2 * a);
return true;
}
else return false;
}
private double a,b,c,x1,x2;
}
public class Tester
{
static void Main()
{
PT pt = new PT();
Console.Write("Nhap he so pt a= ");
pt.A = double.Parse(Console.ReadLine());
Console.Write("Nhap he so pt b= ");
pt.B = double.Parse(Console.ReadLine());
Console.Write("Nhap he so pt c= ");
pt.C = double.Parse(Console.ReadLine());
if (pt.A == 0 && pt.B == 0 & pt.C == 0)
Console.WriteLine("Pt vo so nghiem.");
else
{
if (pt.A == 0)
{
if (pt.pt1(pt.B, pt.C) == true)
Console.WriteLine("PT co mot nghiem : x={0}", pt.X1);
else
Console.WriteLine("Pt vo nghiem.");
}
else if (pt.pt2(pt.A, pt.B, pt.C) == true)
{
if (pt.X1 == pt.X2)
Console.WriteLine("PT co nghiem kep : x1=x2={0}", pt.X1);
else
Console.WriteLine("PT co 2 nghiem thu : x1={0}, x2 ={1}", pt.X1, pt.X2);
}
else Console.WriteLine("Pt vo nghiem.");
}
}
}
}
Bạn đang đọc truyện trên: AzTruyen.Top