一、计算n的m次方(理论上只需要更改数组result[...]的元素个数,可以输出无穷大的结果)
#include<stdio.h>
#define ULLONG (unsigned long long)1000000000000000000ULL
int main(){
int n;
int m;
int cc=0; //监控循环次数
unsigned long long result[10] = {1,0,0,0,0,0,0,0,0,0};
printf("\n\n ");
printf("输入两个数 N 和 M,系统将计算 N 的 0 至 M 的次方:");
scanf("%d %d", &n, &m);
for(int i=0;i<10;i++){
while(cc<=m && result[i] < ULLONG){
for(int j=0;j<i;j++){
result[j+1] = result[j+1] + result[j] / ULLONG;
result[j] = result[j] % ULLONG;
}
printf("\n ");
printf(" %d 的 %-3d 次方是 %llu", n, cc, result[i]);
for (int p = i; p > 0 ; p--) {
if (result[p-1] != 0) {
printf("%018llu", result[p-1]);
}
}
for(int g=0;g<i+1;g++){
result[g]*=n;
}
cc++;
}
}
return 0;
}
标签:实战,int,unsigned,long,C语言,result,printf
From: https://www.cnblogs.com/lyn-/p/18241157