Help with computer science given a natural number N. Calculate: S=1-1 2+1 4-1 8+.+ -1 ^n*1 2^n in Pascal?



The author posted a question in Programming

Help with computer science given a natural number N. Calculate: S=1-1 2+1 4-1 8+.+ -1 ^n*1 2^n in Pascal? and got a better answer

Response from

Response from 0[+++++]
var i,n:integer;s,x:real; begin writeN= ; readln n ; x:=1; s:=0; for i:=1 to n do begin s:=s+x; x:=-x/2 end; writeln s end.

 

To answer the question:

Name*

E-mail:*

Reply text:*
Verification code (enter 22):*