
等答,初学者不太懂,请大家帮忙看看,教教我,谢谢各位,一直都在。
空白的地方应该是填last*=x ,但是输入的x的y次方的结果必须在int的取值范围之内,否则会溢出,而导致结果出错。
测试如下:
参考链接:
c/c++中int,long,long long的取值范围-CSDN博客
文章浏览阅读4.3w次,点赞5次,收藏33次。True2009Fansc/c++中int,long,long long的取值范围:unsigned int 0~4294967295int -2147483648~2147483647unsigned long 0~4294967295long -2147483648~2147483647long long的最大值:92233720368547758...
https://blog.csdn.net/weixin_43107805/article/details/89521922
#include <stdio.h>
int main(void){
int i,x,y,last=1;
printf("Input x and y:");
scanf("%d%d",&x,&y);
// https://blog.csdn.net/weixin_43107805/article/details/89521922
// x的y次方的结果不能超过int的取值范围,否则会溢出,而导致结果出错
for(i=1;i<=y;i++){
last*=x; // last乘以x的值y次,即可让last中存储了x的y次方的结果
}
printf("\nThe last 3 digits of %d ** %d is:%d\n",x,y,last%1000);
return 0;
}
