-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTinhTong.cs
83 lines (71 loc) · 1.88 KB
/
TinhTong.cs
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
78
79
80
81
82
83
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BaiKiemTra
{
class TinhTong
{
int n;
public void nhapn()
{
Console.WriteLine("Nhap n: ");
this.n =Convert.ToInt32(Console.ReadLine());
}
public float tinhTong()
{
float S1 = 0;
float S2 = 0;
for (int i=1;i<=this.n;i++)
{
if (i % 2 == 0)
{
S1 = S1 + -(i);
}
if(i%2!=0)
{
S2=S2+i;
}
}
return S1+S2;
}
public void inTong()
{
Console.WriteLine("Tong la:");
Console.WriteLine(tinhTong());
Console.WriteLine("Tong 2 la:");
Console.WriteLine(tinhTong2());
Console.WriteLine("Tong 3 la:");
Console.WriteLine(tinhTong3());
Console.WriteLine("Tong Uoc la:");
Console.WriteLine(tongUoc());
}
public float tinhTong2()
{
float S3 = 0;
for (float i = 1; i <= this.n; i++)
S3 = S3 + 1 / (i);
return S3;
}
public float tinhTong3()
{
float S4 = 0;
for (int i = 0; i <= this.n; i++)
S4 = S4 + (this.n - i);
return S4;
}
public float tongUoc()
{
float S5 = 0;
for (float i=1;i<this.n;i++)
{
if (this.n%i==0)
{
S5 = S5 + i;
}
}
return S5;
}
}
}