-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkaijyo_test1.cs
More file actions
62 lines (57 loc) · 1.46 KB
/
kaijyo_test1.cs
File metadata and controls
62 lines (57 loc) · 1.46 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace kaijyo
{
class AddCalc
{
// 数値
protected int num;
// 解答
protected int ans;
// numのプロパティ
public int Num
{
set { num = value; }
get { return num; }
}
// 与えられた数から1まで加算する
public void add()
{
ans = 0;
for(int i=num;i>1;i--){
ans += num;
}
Console.WriteLine("{0}から1まで順に足すと{1}である。",num,ans);
}
}
class MulCalc : AddCalc
{
// 階乗の計算
public void mul()
{
ans = 1;
for(int j=num;j>=1;j--){
ans *= j;
}
Console.WriteLine("{0}から1まで順にかけると{1}である。",num,ans);
}
}
class Program
{
static void Main(string[] args)
{
// AddCalcクラスのインスタンス
AddCalc c1 = new AddCalc();
c1.Num = 7;
// MulCalcクラスのインスタンス
MulCalc c2 = new MulCalc();
c2.Num = 7;
// 結果を表示
c2.add();
c2.mul();
}
}
}