2^100是一个很大的数
2^100是一个很大的数,计算机无法直接计算出来,编程求该式的准确结果(从最高位到最低位第一位都要打印出来)[ 本帖最后由 bccn_0934 于 2011-7-11 13:10 编辑 ]
程序代码:#include<stdio.h>
#include<string.h>
char str[1000]="\0";
void func(int n)
{
int i,tmp,c;
if(n==0) str[0]='1';
else
{
func(n-1);
i=0;c=0;
while(str[i]!='\0')
{
tmp=((str[i]-'0')*2+c);
str[i]=tmp%10+'0';
c=tmp/10;
i++;
}
if(c!=0)
{
str[i]=c+'0';
str[i+1]='\0';
}
}
}
int main()
{
int n,i;
while(scanf("%d",&n)!=EOF)
{
memset(str,0,1000);
func(n);i=0;
while(str[i]!='\0')i++;i--;
while(i>=0)
printf("%c",str[i--]);
printf("\n");
}
return 0;
}
