终于写完了。。看来我的编程能力真是很差啊
如下:
#include <stdio.h>
#include <string.h>
#define MAX 200
void chengfa(char * yz1,char *yz2 ,char *jg)
{
int c1[MAX];
int c2[MAX];
int mul[MAX];
char zzjg[MAX];
char mul1[MAX];
int i,j;
int lend=strlen(yz1),lenr=strlen(yz2);
for(i=0;i<MAX;i++)
{
c1[i]=0;
c2[i]=0;
mul[i]=0;
zzjg[i]='/0';
mul1[i]='/0';
}
for(i=0;i<lend;i++)
{
c1[i]=yz1[lend-i-1]-'0';
}
for(i=0;i<lenr;i++)
{
c2[i]=yz2[lenr-i-1]-'0';
}
int carry;
for(i=0;i<lend;i++)
{
carry =0;
for (j=0;j<lenr;j++)
{
mul[j]=(c1[i]*c2[j]+carry)%10;
carry=(c1[i]*c2[j]+carry)/10;
}
if(carry >0)
mul[j++]=carry;
while(mul[j-1]==0)
--j;
int z=0;
int l=0;
for (z=0;z<i;z++)
{
mul1[z]='0';
}
for(l=0;l<j;l++)
mul1[z++]=mul[l]+'0';
mul1[z]='/0';
int m=0;
carry=0;
int lenp=strlen(mul1);
int lenq=strlen(zzjg);
int lenmin=0;
lenmin=lenp<lenq ?lenp:lenq;
int w=0;
carry=0;
for (m=0;m<lenmin;m++)
{
w=zzjg[m]+mul1[m]+carry-'0'-'0';
zzjg[m]=w%10+'0';
carry=w/10;
}
while (m<lenp)
{
zzjg[m]=(mul1[m]-'0'+carry)%10+'0';
carry=(mul1[m]-'0'+carry)/10;
m++;
}
while (m<lenq)
{
w=zzjg[m]+carry-'0';
zzjg[m]=w%10+'0';
carry=w/10;
m++;
}
if(carry>0)
{
zzjg[m++]=carry+'0';
}
zzjg[m]='/0';
}
int lenjg=strlen(zzjg);
int a;
for (int asd=0;i<200;i++)
{
jg[asd]='/0';
}
for(a=0;a<lenjg;a++)
{
jg[a]=zzjg[lenjg-a-1];
}
jg[a]='/0';
}
int quxsd(char * from,char * to)
{
int i=0,j=0,k=0;
while(from[i]!='.'&&from[i]!='/0')
{
to[j++]=from[i++];
}
k=i++;
while(from[i]!='/0')
{
to[j++]=from[i++];
}
to[j]='/0';
return i-k-1;
}
void jiecheng(char * dishu ,int zhishu,char * jieguo)
{
if (strcmp(dishu,"0")==0)
{
printf("0/n");
return;
}
if(zhishu==0)
{
printf("1/n");
return;
}
int i=0;
int sig;
char di[MAX];
for (i=0;i<MAX;i++)
{
di[i]='/0';
}
int xsds=quxsd(dishu,di);
strcpy(jieguo,di);
for(i=0;i<(zhishu-1);i++)
{
chengfa(jieguo,di,jieguo);
}
if (!xsds)
{
printf("%s/n",jieguo);
return;
}
int counter=0;
for(sig=MAX-1; sig>=0; sig--)
{
if(jieguo[sig]=='/0')
counter=1;
if(counter)
{
if(!jieguo[sig]||jieguo[sig]=='0' )
continue;
else
break;
}
}
int yiwei=xsds*(zhishu);
int lenjg=strlen(jieguo);
// int myresult[MAX];
// memset(myresult,0,sizeof(int)*MAX);
// for (i=0;i<lenjg;i++)
// {
// myresult[i] = jieguo[i]-'0';
// }
if (yiwei > lenjg)
{
printf(".");
for (i=0;i<(yiwei-lenjg);i++)
{
printf("0");
}
for(i=0; i<lenjg;i++)
{
printf("%c",jieguo[i]);
}
}
else
{
for(i=0; i<(lenjg-yiwei) ;i++)
{
printf("%c",jieguo[i]);
}
int allzero=0;
for (i=0;i<(sig-(lenjg-yiwei)+1);i++)
{
if (jieguo[i+lenjg-yiwei]!='0')
{
allzero=1;
}
}
if (allzero)
{
printf(".");
for(i=0; i<(sig-(lenjg-yiwei)+1) ;i++)
{
printf("%c",jieguo[i+lenjg-yiwei]);
}
}
}
printf("/n");
}
int main()
{
char a[MAX];
char c[MAX];
int b=0;
int i;
char m[6];
for (i=0;i<6;i++)
{
m[i]='/0';
}
while(scanf("%s%d",&m,&b)==2)
{
for ( i=0;i<6;i++)
{
if (m[i]!='/0'||m[i]!='32')
{
a[i]=m[i];
if (i==5)
{
a[++i]='/0';
break;
}
}
else
{
a[i]='/0';
break;
}
}
for(i=0;i<MAX;i++)
{
c[i]='/0';
}
jiecheng(a,b,c);
}
return 0;
}