程序代码:
#include <stdio.h>
#include <math.h>
#include <string.h>
#define N 10001
int main(void)
{
char a1[N];
int a2[N], b[N], c[N] = { 0 }, d[N] = { 0 };
int n, m, i, j = 0, k;
int len, len1, mul;
printf("Please input a string a1:");
gets(a1);
len = strlen(a1);
for (i = 0; i < len; i++)
{
if (a1[i] < 48 || a1[i] > 57)
{
printf("Illegal input !\n");
printf("Enter again:");
gets(a1);
break;
}
}
printf("\n");
for (i = len - 1; i >= 0; i--)
{
b[j] = a2[j] = a1[i] - 48;
printf("%d", b[j]); j++;
}
printf("\n\nPlease input m:");
scanf("%d", &m);
len1 = len;
while (m - 1)
{
for (i = 0; i < len; i++)
{
k = i;
for (j = 0; j < len1; j++)
{
mul = b[i] * a2[j] ;
if (mul + c[k] + d[k] > 9)
{
c[k + 1] = (mul + c[k] + d[k]) / 10;
d[k] = (mul + c[k] + d[k]) % 10;
}
else
d[k] = mul + c[k] + d[k];
k++;
}
d[k] = c[k];
for (j = 0; j <= k; j++)
c[j] = 0;
}
len1 = k + 1;
for (j = 0; j <= len1; j++)
{
a2[j] = d[j];
d[j] = 0;
}
m--;
}
printf("\n");
for (i = len1 ; i >= 0; i--)
{
if (a2[i])
{
j = i; break;
}
}
for (i = j; i >= 0; i--)
printf("%d", a2[i]);
printf("\n\n");
printf("Please input n & m:");
scanf("%d%d", &n, &m);
printf("\n\n%f\n\n", pow(n, m));
return 0;
}
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
哈哈
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
[
本帖最后由 有容就大 于 2012-1-19 07:28 编辑 ]