S←1 For i from 1to4 S←S+2^iEND FOR Print S

来源:学生作业帮助网 编辑:作业帮 时间:2024/06/28 15:50:02

S←1 For i from 1to4 S←S+2^iEND FOR Print S
S←1 For i from 1to4 S←S+2^i
END FOR Print S

S←1 For i from 1to4 S←S+2^iEND FOR Print S
s=1;
i=1, s=1+2^1=3;
i=2, s=3+2^2=7;
i=3, s=7+2^3=15;
i=4, s=15+2^4=31;

所以打印 31

相当于等比数列求和,从2的0次方加到2的4次方
S=1+2^1+2^2+2^3+2^4=(1*(1-2^5))/(1-2)=2^5-1=31