一个简单的pascal程序

来源:百度知道 编辑:UC知道 时间:2024/05/13 02:22:28
国际象棋盘中,第1格中放1粒米,第2格中放2粒米,第3格中放4粒米,第4格中放8粒米,第5格中放16粒米......问:16个格子总共可以放多少粒米?
(第i个格子:2的(i-1)次方)

并请高手写出x的(..)次方的程序,并解释为什么

谢谢!!!!!!!!!!!!!!!

问题程序:
program a1;
const n=16;
var x,p,i:longint;
begin
write('x=');readln(x);
p:=1;
for i:=1 to n-1 do p:=p*p;
writeln(x,'^',n,'=',p);
end.
x的(..)次方的程序:
program a2;
var x,n,p,i:longint;
begin
write('x=');readln(x);
write('n=');readln(n);
p:=1;
for i:=1 to n-1 do p:=p*p;
writeln(x,'^',n,'=',p);
end.

程序如下,调试通过,保证运行:

{$apptype console}
program exp;
var x,n,p,i:integer;
begin
write('x=');readln(x);
write('n=');readln(n);
p:=1;
for i:=1 to n do p:=p*x;
writeln(x,'的',n,'次方=',p);
end.

计算x的n次方,结果就是是n个x相乘,很简单。

楼上的:你没有注意到数据规模
integer的 最大值是128
远远不够
用longint