Chủ Nhật, 26 tháng 6, 2022

TONG3 C++

#include <bits/stdc++.h>
using namespace std;

int n;
float s1,s2;
int main()
{
    freopen("tong3.inp","r",stdin);
    freopen("tong3.out","w",stdout);
    cin>>n;
    // Tinh S1
    s1=0;
    for(int i=1;i<=n;i++) 
        s1=s1+(float)1/(i*(i+1));
    cout<<fixed<<setprecision(2);
    cout<<"S1 = "<<s1<<endl;
    // Tinh S2
    s2=0;
    for(int i=1;i<=n;i++) 
        s2=s2+(float)i/(i+1);
    cout<<"S2 = "<<s2;
}

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.