[題目分析]這是以讀入數據的順序為相反順序進行累乘問題可將讀入數據放入棧中到輸入結束將棧中數據退出進行累乘累乘的初值為
PROC test;
CONST maxsize=;
VAR s:ARRAY[maxsize] OF integer topsuma:integer;
[top:=; sum:=;//
read(a);
WHILE a<> DO
[top:=top+; s[top]:=a; read(a); ]
write(sum:);
WHILE top> DO
[sum:=sum*s[top]; top:=top; write(sum:);]
ENDP;
[題目分析] 本題與第題基本相同不同之處就是求和另外用C描述
int test;
{int xsum=top=s[];
scanf(%d&x)
while (x<>)
{s[++top]:=a; scanf(%d&x); }
printf(sum:);
while (top)
{sum+=s[top]; printf(sum:); }
};
int Ack(int mn)
{if (m==) return(n+);
else if(m!=&&n==) return(Ack(m));
else return(Ack(mAck(mm));
}//算法結束
()Ack()的計算過程
Ack()=Ack(Ack()) //因m<>n<>而得
=Ack(Ack()) //因m<>n=而得
=Ack(Ack(Ack())) // 因m<>n<>而得
= Ack(Ack(Ack())) // 因m<>n=而得
=Ack(Ack()) // 因m=而得
=Ack() // 因m=而得
=Ack(Ack()) //因m<>n<>而得
= Ack(Ack(Ack())) //因m<>n<>而得
= Ack(Ack(Ack(Ack()))) //因m<>n<>而得
= Ack(Ack(Ack(Ack()))) //因m<>n=而得
= Ack(Ack(Ack())) //因m=而得
= Ack(Ack()) //因m=而得
= Ack() //因n=而得
= //因n=而得
()int Ackerman( int m int n)
{int akm[M][N];int ij;
for(j=;j<N;j++) akm[][j];=j+;
for(i=;i<m;i++)
{akm[i][]=akm[i][];
for(j=;j<N;j++)
akm[i][j]=akm[i][akm[i][j]];
}
return(akm[m][n]);
}//算法結束
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
From:http://tw.wingwit.com/Article/program/sjjg/201311/22694.html