Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int bai_1(int n)
- {
- int s = 0;
- for (int i = 1; i <= n; i++)
- s += i;
- return s;
- }
- int bai_2(int n)
- {
- int s = 0;
- for (int i = 1; i <= n; i++)
- s += i * i;
- return s;
- }
- float bai_3(int n)
- {
- float s = 0;
- for (int i = 1; i <= n; i++)
- s += 1.0f / i;
- return s;
- }
- float bai_4(int n)
- {
- float s = 0;
- for (int i = 1; i <= n; i++)
- s += 1.0f / (2 * i);
- return s;
- }
- float bai_5(int n)
- {
- float s = 0;
- for (int i = 0; i <= n; i++)
- s += 1.0f / (2 * i + 1);
- return s;
- }
- float bai_6(int n)
- {
- float s = 0;
- for (int i = 1; i <= n; i++)
- s += 1.0f / (i * (i + 1));
- return s;
- }
- float bai_7(int n)
- {
- float s = 0;
- for (int i = 1; i <= n; i++)
- s += i * 1.0f / (i + 1);
- return s;
- }
- float bai_8(int n)
- {
- float s = 0;
- for (int i = 1; i <= n; i++)
- s += (2 * i + 1) * 1.0f / (2 * i + 2);
- return s;
- }
- void main()
- {
- int n = 5;
- cout << "Bai 1: \n\tn = " << n << "\n\tKet qua: " << bai_1(n) << endl;
- cout << "Bai 2: \n\tn = " << n << "\n\tKet qua: " << bai_2(n) << endl;
- cout << "Bai 3: \n\tn = " << n << "\n\tKet qua: " << bai_3(n) << endl;
- cout << "Bai 4: \n\tn = " << n << "\n\tKet qua: " << bai_4(n) << endl;
- cout << "Bai 5: \n\tn = " << n << "\n\tKet qua: " << bai_5(n) << endl;
- cout << "Bai 6: \n\tn = " << n << "\n\tKet qua: " << bai_6(n) << endl;
- cout << "Bai 7: \n\tn = " << n << "\n\tKet qua: " << bai_7(n) << endl;
- cout << "Bai 8: \n\tn = " << n << "\n\tKet qua: " << bai_8(n) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement