LÆp víi sè lÇn cha biÕt tríc, C©u lÖnh WHILE - do.[r]
(1)Bµi 10 (2) LÆp víi sè lÇn cha biÕt tríc, C©u lÖnh WHILE - WHILE <®iÒu kiÖn> DO <C©u lÖnh>; VÝ dô: TÝnh tæng 1 1 S= + + + + a a+1 a+2 a + 100 cho tíi : 0,0001 víi a d ¬ng a+N * ThuËt to¸n: B1: NhËp sè a; B2: S:=1/a; N:=0; B3: Khi 1/(a+N) >=0,0001 th× N := N + 1; S := S + 1/(a+ N) råi quay l¹i B3; B4: §a S råi kÕt thóc (3) LÆp víi sè lÇn cha biÕt tríc, C©u lÖnh WHILE - * Ch¬ng tr×nh: Program Tong_lap_kbt; Uses crt; Var S : real; a, N : integer; BEGIN Clrscr ; Write(‘nhap so a = ’); Readln(a); S:=1/a; N:= 0; While 1/(a+N) >= 0,0001 Begin N := N + 1; S := S + 1/(a + N); End; Writeln(‘Tong S = ’, S:8:2); Readln END (4)