lập trình tính tổng 1/2+1/3+-+1/n với n nhập từ bàn phím với lệnh while…do

lập trình tính tổng 1/2+1/3+….+1/n với n nhập từ bàn phím với lệnh while…do

0 bình luận về “lập trình tính tổng 1/2+1/3+-+1/n với n nhập từ bàn phím với lệnh while…do”

  1. program oken;

    uses crt;

    var a: real;

    i,n:longint;

    begin

    clrscr;

    write(‘nhap n: ‘); readln(n);

    a:=0; i:=1;

    while i<=n do

    begin

    a:=a+1/i;

    i:=i+1;

    end;

    writeln(‘A=’,a:0:3);

    readln;

    end.

    Bình luận
  2. ko while do dc ko ban =(

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        double n,total=0;
        cin>>n;
        for(int i=1;i<=n;i++){
            total+=1/(float)i;
        }
        cout<<total;
        //samon247
        return 0;
    }

    Bình luận

Viết một bình luận