1.请将以下程序段表示的计算公式写出来(假设X的值已给出)E:=1;A:=1;FORN:=1TO10DOBEGINA:=A*X/N;E:=E+A;ENDFOR;写出所表示的公式。2.阅读下列程序段,写出程序段运行后变量X的值。X1:=3;X2:=8;FORI:=1TO5DOBEGIN{循环结构,应用数据轮换方式,求两个数和的2倍。}X:=(X1+X2)*2;X1:=X2;X2:=X;END;WRITELN(‘X=’,X);3.阅读下列程序段,写出程序运行后数组元素A1,A2,…,A11中的值。A[1]:=1;A[2]:=1;K:=1;REPEATA[K+2]:=1;FORI:=K+1DOWNTO2DOA[I]:=A[I]+A[I-1];K:=K+1;UNTILK=10;4.programexp1(input,output);vari,s,max:integer;a:array[1..10]ofinteger;beginfori:=1to10doread(a[i]);max:=a[1];s:=a[1];fori:=2to10dobeginifs0thens:=0;s:=s+a[i];ifsmaxthenmax:=send;writeln(‘max=’,max)end.输入:-213-1478-1-18246输出:max=输入:89-124651115-289输出:max=5.programexp2(input,output);constn=5;vari,j,k:integer;a:array[1..2*n,1..2*n]ofinteger;begink:=1;fori:=1to2*n-1doifi=nthenifodd(i)thenforj:=idownto1dobegina[i-j+1,j]:=k;k:=k+1endelseforj:=1toidobegina[i-j+1,j]:=k;k:=k+1;endelseifodd(i)thenforj:=ndowntoi-n+1dobegina[i-j+1,j]:=k;k:=k+1;endelseforj:=i-n+1tondobegina[i-j+1,j]:=k;k:=k+1;end;fori:=1tondobeginforj:=1tondowrite(a[i,j]:3);writelnend;end.6.programexp3(input,output);constn=10;vars,i:integer;functionco(i1:integer):integer;varj1,s1:integer;begins1:=n;forj1:=(n-1)downto(n-i1+1)dos1:=s1*j1div(n-j1+1);co:=s1end;begins:=n+1;fori:=2tondos:=s+co(i);writeln(‘s=’,s);end.7.programexp4(input,output);constn=3;vari,j,s,x:integer;p:array[0..n+1]ofinteger;g:array[0..100]ofinteger;beginfori:=0to100dog[i]:=0;p[0]:=0;p[n+1]:=100;fori:=1tondoread(p[i]);readln;fori:=0tondoforj:=i+1ton+1dog[abs(p[j]-p[i])]:=g[abs(p[j]-p[i])]+1;s:=0;fori:=0to100doifg[i]0thenbeginwrite(i,:4);s:=s+1;end;writeln;writeln(‘s=’,s);writeln(‘inputdata:’);readln(x);writeln(g[x])end.输入:102065inputdata:10输出:8.programexcpl;varx,y,y1,jk,j1,g,e:integcr;a:array[l..20]of0..9;beginx:=3465;y:=264;jk:=20;forj1:=1to20doa[j1]:=0;whiley<>0dobeginy1:=ymod10;y:=ydiv10;whiley1<>0dobeging:=x;fore:=jkdownto1dobeging:=g+a[e];a[e]:=gmod10;g:=gdiv10end;y1:=y1-1end;jk:=jk-1end;j1:=1;whilea[j1]=0doj1:=j1+1;forjk:=j1to20dowrite(a[jk]:4);writelnend.9.programexcp2vari,j:integer;a:array[1..14]ofinteger;proceduresw(i1,j1:integer);vark1:integer;beginfork1:=1to(j1-i1+1)div2dobegina[i1+k1-1]:=a[i1+k1-1]+a[j1-k1+1];a[j1-k1+1]:=a[i1+k1-1]-a[j1-k1+1];a[i1+k1-1]:=a[i1-k1+1]-a[j1-k1+1];end;end;beginj:=211;fori:=1to14dobegina[i]:=i;j:=j-iend;sw(1,4);sw(5,10);sw(11,14);sw(1,14);fori:=1to14dobeginifjmodi=1thenwrite(a[i]:3);j:=j-a[i];end;writelnend.10.programnoi_002;vari,j,l,n,k,s,t:integer;b:array[1..10]of0..9;beginreadln(l,n);s:=l;k:=1;t:=l;whiless:=s-t;n:=n-s-1;fori:=1to10dob[i]:=0;j:=11;whilen0dobeginj:=j-1;b[j]:=nmodl;n:=ndivlend;fori:=10-k+1to10dowrite(chr(ord('a')+b[i]));end.输入:4167输出:11.programnoi_004;vari,j,j1,j2,p,q:integer;p1:boolean;b,c:array[1..100]ofinteger;beginreadln(q,p);j:=1;p1:=true;b[j]:=q;j1:=0;while(q0)andp1dobeginj1:=j1+1;c[j1]:=q*10divp;q:=q*10-c[j1]*p;ifq0thenbeginj2:=1;while(b[j2]q)and(j2=j)doj2:=j2+1;ifb[j2]=qthenbeginp1:=false;write('0.');fori:=1toj2-1dowrite(c[i]:1);write('{');fori:=j2toj1dowrite(c[i]:1);writeln('}')endelsebeginj:=j+1;b[j]:=qendendend;ifq=0thenbeginwrite('0.');fori:=1toj1dowrite(c[i]:1);writelnend;readlnend.输入①18输出输入②27输出12.programchu7_1;functionfun(x:integer):integer;beginif(x=0)or(x=1)thenfun:=3elsefun:=x-fun(x-2)end;beginwriteln(fun(9));readln;end.13.programchu7_2;vari,j,f:integer;a:array[1..8]ofinteger;beginfori:=1to8dobeginf:=imod2;iff=0thena[i]:=0elsea[i]:=1;forj:=1toidoiff=0thena[i]:=a[i]+jelsea[i]:=a[i]*jend;fori:=1to8dowrite(a[i]:5);end.14.programchu7_3;varp,q,s,t:integer;beginreadln(p);forq:=p+1to2*pdobegint:=0;s:=(p*q)mod(q-p);ifs=0thenbegint:=p+q+(p*q)div(q-p);write(t:4);end;end;readlnend.输入:12输出:15.prgoramchu7_4;varn,k,i:integer;a:array[1..40]ofinteger;procedurefind(x:integer);vars,i1,j1:integer;p:boolean;begini1:=0;p:=true;whilepdobegini1:=i1+1;s:=0;forj1:=1tondoifa[j1]a[i1]thens:=s+1;if(s=x-1)thenbeginwriteln(a[i1]);p:=falseend;endend;beginreadln(n,k);fori:=1tondoread(a[i]);find(k);find(n-k);end.输入:1041234565678779012013输出:16.programexp1;vari,j,k,n,,l0,l1,lk:integer;a:array[0..20]ofinteger;beginreadln(n,k);fori:=0ton-1doa[i]:=i+1;a[n]:=a[n-1];l0:=n-1;lk:=n-1;fori:=1ton-1dobeginl1:=l0-k;if(l10)thenl1:=l1+n;if(l1=lk)thenbegina[l0]:=a[n];lk:=lk-1;a[n]:=a[lk];l0:=lkend;elsebegina[l0]:=a[l1];l0:=l1;end;end;a[l0]:=a[n];fori:=0ton-1dowrite(a[i]:40);writeln;end.输入:104输出:17.programexp2;varn,jr,jw,jb:integer;ch1:char;ch:array[1..20]ofchar;beginreadln(n);fori:=1tondoread(ch[i]);jr:=1;jw:=n;jb:=n;:while(jr=jw)dobeginif(ch[jw]='R')thenbeginch1:=ch[jr];ch[jr]:=ch[jw];ch[jw]:=ch1;jr:=jr+13endelseifch[jw]='W'thenjw:=jw-1elsebeginch1:=ch[jw];ch[jw]:=ch[jb];ch[jb]:=ch1;jw:=jw-1;jb:=jb-1;endend;fori:=1tondowrite(ch[i]);writeln;end.输入:10RBRBWWRBBR输出:18.pmgramexp3;vari,j,p,n,q,s:integer;a:array[1..20]ofinteger;beginreadln(p,n,q);j:=21;while(n0)dobeginj:=j-1;a[j]:=nmod10;n:=ndiv10;end;s:=0;fori:=jt020dos:=s*p+a[i];writeln(s);j:=21;while(so)dobeginj:=j-1;a[j]:=smodq;s:=sdivq;end;fori:=jto20dowrite(a[i]);readln;end.输入:730518输出:19.programprograml;vara,x,y,okl,ok2:integer;begina:=100;x:=l0;y:=20;okl:=5;ok2: