分享一首歌
出租车价钱计算
1 | using System; |
简易计算器
1 | using System; |
出行计算
1 | using System; |
一元二次方程计算
1 | using System; |
定义类并实现输出
1 | using System; |
计算面积与周长
- 1 基础算法-(计算圆)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36using System;
namespace ConsoleApp1
{
public class Circle
{
public double radius;
//计算圆的周长
public double C()
{
return 2 * Math.PI * radius;
}
//计算圆的面积
public double Area()
{
return Math.PI * radius * radius;
}
}
internal class Problem
{
static void Main(string[] args)
{
//创建两个Circle对象
Circle obj1 = new Circle();
Circle obj2 = new Circle();
//第一个圆输出
Console.WriteLine("请输入第一个圆的半径:");
obj1.radius = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("第一个圆的周长为{0:0.00},面积为:{1:0.00}", obj1.C(), obj1.Area());
//第二个圆输出
Console.WriteLine("请输入第二个圆的半径:");
obj2.radius = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("第二个圆的周长为{0:0.00},面积为:{1:0.00}", obj2.C(), obj2.Area());
}
}
}
- 2 使用继承和属性-(计算矩形)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78using System;
namespace ConsoleApp1
{
class Shape
{
private string name;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public Shape(string name)
{
this.Name = name;
}
}
class rectangle:Shape
{
private double len;
private double width;
public double Len
{
get
{
return len;
}
set
{
len = value;
}
}
public double Width
{
get
{
return width;
}
set
{
width = value;
}
}
public rectangle(double len, double width,string name):base(name)
{
this.Len = len;
this.Width = width;
}
public void getArea()
{
Console.WriteLine("编号:{0},面积:{1}",Name,Len * Width);
}
public void getCircumference()
{
Console.WriteLine("编号:{0},周长:{1}", Name,2*(Len+Width));
}
}
class Program
{
static void Main(string[] args)
{
Console.Write("请输入长:");
double Width = double.Parse(Console.ReadLine());
Console.Write("请输入宽:");
double Len = double.Parse(Console.ReadLine());
rectangle Rect = new rectangle(Len, Width, "Rec");
Rect.getArea();
Rect.getCircumference();
}
}
}
密码校验
1 | using System; |
定义Book类格式化输出book信息
1 | using System; |
银行存款
1 | using ConsoleApp3; |
百钱买百鸡
1 | using System; |
素数计算
1 | using System; |
珠穆朗玛-对折
1 | using System; |
分数计算
1 | using System; |
杨辉三角
1 | using System; |