问答题
下列给定程序中,函数proc()的功能是:求整数x的y次方的低3位值。
例如,整数6的5次方为7776,此值的低3位值为776。
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdio.h>
long proc(int x, int y, long*p)
{
int i;
long t=1;
//****found****
for(i=1; i<y; i++)
t=t*x;
*p=t;
//****found****
t=t/1000;
return 1;
}
void main()
{
long t, r;
int x, y;
printf("/nInput x and y: "); scanf
("%1d%1d", &x, &y);
t=proc(x, y, &r):
printf("/n/nx=%d, y=%d, r=%1d, last=
%1d/n/n", x, y, r, t);
}