im programing student our master wanna me make this program with 0.1 accuracy i use "writeln(h:nr:nl)" that was wrong
this is original program 2 cal sum of 1¹-(2³/3!)+(2⁵/5!)-(2⁷/7!)+(2⁹/9!)…+-(2ⁿ...

program p1;
var n,i,sign: integer; h,p,fac: real;
begin
h:=1; p:=2; sign:=-1; fac:=1;
readln(n);
for i:=2 to n do
begin
fac:=fac*i;
p:=p*2;
if (i mod 2)<>0 then
begin
h:=h+sign*p/fac;
sign:=-sign;
end;
i:=i+1;
end;
writeln(h);
end.

please help me

[[I][/I]code=Pascal[I][/I]]

writeln( h:0:1 );

[[I][/I]/code[I][/I]]

This prints a real value (h) with an indefinite number of whole digits (0) and only one fractional digit (1).

Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.