Diễn đàn sinh viên công nghệ thông tin, chia sẻ, giao lưu, học hỏi. Kết nối ... Những ngôn ngữ cơ bản mà bạn cần phải nắm nếu muốn thành 1 lập trình viên ...VuaTenMien.Com
Thứ Tư, 27 tháng 2, 2013
Code C#: Giải phương trình bậc 2 (Console)
/* Giải và biện luận phương trình bậc 2 (sử dụng ứng dụng Console) */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GiaiPT_bac2{
class Program{
static void Main(string[] args){
float a, b, c;
string xau;
// Nhap a,b,c
Console.WriteLine("\n Nhap he so: ");
Console.Write("\n a= ");
xau = Console.ReadLine();
a = float.Parse(xau);
Console.Write("\n b= ");
xau = Console.ReadLine();
b = float.Parse(xau);
Console.Write("\n c= ");
xau = Console.ReadLine();
c = float.Parse(xau);
// Giai va bien luan
if (a == 0)
if (b == 0)
if (c == 0)
Console.WriteLine("\n Phuong trinh vo so nghiem");
else
Console.WriteLine("\n Phuong trinh vo nghiem");
else
Console.WriteLine("\n Phuong trinh co 1 nghiem x= {0}", c / b);
else {
float delta=b*b-4*a*c;
if(delta<0)
Console.WriteLine("\n Phuong trinh vo nghiem");
if(delta==0)
Console.WriteLine("\n Phuong trinh co nghiem kep x1=x2= {0}",-b/(2*a));
if (delta > 0){
float x1, x2;
x1 = (-b - (float)Math.Sqrt(delta)) / (2 * a);
x2 = (-b + (float)Math.Sqrt(delta)) / (2 * a);
Console.WriteLine("\n Phuong trinh co 2 nghiem x1= {0}; x2= {1}", x1, x2);
}
}
}
}
}
Đăng ký:
Đăng Nhận xét (Atom)
Bài đăng phổ biến
-
import java.io.*; public class Test_Ngto{ public static void main(String args[]){ InputStream is = System.in; ...
-
import java.io.*; public class ReadLine{ public static void main(String args[]){ InputStreamReader isr = new InputStreamReader...
-
1. Hãy xây dựng lớp Diem cùng với các đối tượng điểm trong mặt phẳng và các phương thức sau: - Phương thức khởi tạo - Phương...
-
<html> <head> <title>Giai phuong trinh bac 2</title> <script language="JavaScript"> function giai(fo...
-
import java.io.*; public class Test_Tng{ public static void main(String args[]){ InputStream is = System.in; ...
-
<%@ Page Language="VB" Debug="true" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespa...
-
<html> <head><script LANGUAGE="JavaScript"> function a_plus_b(form) { a=eval(form.a.value) ...
-
import java.io.*; public class Gptb2{ public static void main(String args[]){ InputStreamReader isr = new InputStream...
-
<html> <head> <title>giai phuong trinh bac 1</title> <script language="JavaScript"> function giai(fo...
-
<%@ Page Language="VB" Debug="true" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespa...
Không có nhận xét nào:
Đăng nhận xét