Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include<iostream>

#include<cmath>
using namespace std;
int Tong(int n)
{
double Sum = 0;
for (int i = 1; i <= n; i++)
{
Sum += (float)1 / i;
}
return floor(Sum);
}
void CongThucDemThuCong(int n)
{
int S = 0;
for (int i = 1; i <= n; i++)
{
S += Tong(i);
}
int gan = 3 + 3 * n + 2 * S;
int ss = 2 * n + 1 + S;
cout << "So phep gan (dem thu cong): " << gan << endl;
cout << "So phep so sanh (dem thu cong): " << ss << endl;
}
void KhiChayChuongTrinh(int n)
{
int i = 1, ret = 0;
float s = 0;
int gan = 3;
int ss = 1;
while (i <= n)
{
int j = 1;
s += (float)1 / i;
ss++;
while (j <= s)
{
ret = ret + i * j;
j = j + 1;
gan += 2;
ss++;
}
i = i + 1;
gan += 3;
ss++;
}
cout << "So phep gan (khi chay chuong trinh): " << gan << endl;
cout << "So phep so sanh (khi chay chuong trinh): " << ss << endl;

}
int main()
{
for (int n = 1; n <= 20; n++)
{
CongThucDemThuCong(n);
KhiChayChuongTrinh(n);
}

return 0;
}

You might also like