Open nhokhacam1 opened 4 years ago
using System;
using System.ComponentModel.DataAnnotations;
namespace ConsoleApp1
{
class Program
{
static double tong(double a,double b)
{
return a + b;
}
static void inTong(double a,double b)
{
double c = tong(a, b);
Console.WriteLine("tong a va b: " + c);
}
static void Main(string[] args)
{
double a = 57, b = 8.5;
inTong(a,b);
}
}
}
double: 3.5,-2.1,0.1,2,1,3,6
static double thuong(int a, int b)
{
return (double)a / b;
}
ép kiểu
using System;
using System.ComponentModel.DataAnnotations;
namespace ConsoleApp1
{
class Program
{
static double tong(double a,double b)
{
return a + b;
}
static double thuong(int a, int b)
{
return (double)a / b;
}
static void inThuong(int a,int b)
{
double d = thuong(a, b);
Console.WriteLine("thuong a va b: " + d);
}
static void inTong(double a,double b)
{
double c = tong(a, b);
Console.WriteLine("tong a va b: " + c);
}
static void Main(string[] args)
{
double a = 5, b = 8.5;
inTong(a,b);
inThuong((int)a, (int)b);
}
}
}
using System;
using System.Security.Cryptography;
namespace ConsoleApp1
{
class Program
{
static double tinhTong(double a, double b)
{
return a + b;
}
static double tinhHieu(double a, double b)
{
return a - b;
}
static double tinhTich(double a, double b)
{
return a * b;
}
static double tinhThuong(double a, double b)
{
return a / b;
}
static void menu()
{
int luachon;
double a, b;
Console.Write("a:");
a = double.Parse(Console.ReadLine());
Console.Write("b:");
b = double.Parse(Console.ReadLine());
Console.WriteLine("------------menu-----------");
Console.WriteLine("1 tong");
Console.WriteLine("2 hieu");
Console.WriteLine("3 tich");
Console.WriteLine("4 thuong");
// nhap lua chon
luachon = int.Parse(Console.ReadLine());
switch (luachon)
{
case 1:
//TODO: tong
double tong = tinhTong(a, b);
Console.WriteLine("tong = {0}",tong);
break;
case 2:
//TODO: hieu
double hieu = tinhHieu(a, b);
Console.WriteLine("hieu = {0}",hieu);
break;
case 3:
//TODO: tich
double tich = tinhTich(a, b);
Console.WriteLine("tich = {0}",tich);
break;
case 4:
//TODO: thuong
double thuong = tinhThuong(a, b);
Console.WriteLine("thuong = {0}",thuong);
break;
}
}
static void Main(string[] args)
{
menu();
}
}
}