Đã chỉnh hết mức mà chương trình vẫn báo lỗi "Cannot implicitly convert type 'double' to 'float'. An explicit conversion exists (are you missing a cast?)" ai giải thích dùm mình với....
Nếu có thể thì bạn nào share cho mình 1 hàm "tính giá trị của 1 đơn thức với giá trị x do ng dùng nhập" với. Phần này mới bắt đầu học chả hiểu gì hết.nó ko giống C++ gì cả huhu.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bàitậptuần1_web2
{
class DonThuc
{
public int[] hs;
public int[] sm;
public int n;
public void nhap()
{
n = int.Parse(Console.ReadLine());
hs = new int[n];
sm = new int[n];
for (int i = 0; i < n; i++)
{
Console.Write("Nhap he so cua don thuc {0}: ",i+1);
hs[i] = int.Parse(Console.ReadLine());
Console.Write("Nhap so mu cua don thuc {0}: ",i+1);
sm[i] = int.Parse(Console.ReadLine());
}
}
public void xuat()
{
Console.Write("Hien thi cac don thuc: \n");
for (int i = 0; i < n; i++)
{
Console.WriteLine("Don thuc {0} la: {1} X ^ {2}",i+1,hs[i],sm[i]);
}
}
public float TinhGiaTri()
{
Console.Write("Nhap so thu tu don thuc can tinh gia tri");
int q = int.Parse(Console.ReadLine());
Console.Write("Nhap gia tri x: ");
int x = int.Parse(Console.ReadLine());
float kq = hs[q] * Math.Pow((double)x, (double)sm[q]);
return kq;
}
static void Main(string[] args)
{
Console.Write("Nhap so luong don thuc: ");
DonThuc k = new DonThuc();
k.nhap();
k.xuat();
float kq = k.TinhGiaTri();
Console.WriteLine("Gia tri cua don thuc la: {0}",kq);
}
}
}