thuzhangga 于 2016.01.26 16:06 提问

int *cal(int *a,int num)
{
int digit=sizeof(a)/sizeof(int);
int *result=a;
int *b=(int *)calloc(digit+1,sizeof(int));
for(int i=0;i {
b[i+1]=(result[i]*num+b[i])/10;
result[i]=(result[i]*num+b[i])%10;
}
if(b[digit]>=1)
{
int *c=result;
digit++;
result=(int *)malloc(sizeof(int)*digit);
for(int two=0;two<digit-1;two++)
result[two]=c[two];
result[digit-1]=b[digit-1];
}
free(b);
return result;
}

int *d=cal(a,4);
for(int three=0;three<4;three++)
printf("%d",d[three]);

4个回答

qq_27183003      2016.01.26 17:20

#include"stdio.h"
#include"stdlib.h"
int *cal(int *a,int digit, int num)
{
int *b=(int *)calloc(digit+1,sizeof(int));
for(int i=0;i<digit;i++)
{
b[i+1]=(a[i]*num+b[i])/10;
b[i]=(a[i]*num+b[i])%10;
}

return b;
}
int main()
{
int a[4]={4,2,2,4};
int *d=cal(a,4,4);

int m;
if(d[4]) m=5;
else m=4;
for(int three=m-1;three>=0;three--)
printf("%d",d[three]);
free(d);
}

qq_27183003      2016.01.26 16:32

thuzhangga   2016.01.26 16:56

#include"stdio.h"
#include"stdlib.h"
int *cal(int *a,int num)
{
int digit=sizeof(a)/sizeof(int);
int *result=a;
int *b=(int *)calloc(digit+1,sizeof(int));
for(int i=0;i {
b[i+1]=(result[i]*num+b[i])/10;
result[i]=(result[i]*num+b[i])%10;
}
if(b[digit]>=1)
{
int *c=result;
digit++;
result=(int *)malloc(sizeof(int)*digit);
for(int two=0;two<digit-1;two++)
result[two]=c[two];
result[digit-1]=b[digit-1];
}
free(b);
return result;
}
void main()
{
int a[4]={1,2,3,4};
int *d=cal(a,4);
for(int three=0;three<4;three++)
printf("%d",d[three]);
}

qq_27183003      2016.01.26 17:02
int digit=sizeof(a)/sizeof(int);

#include"stdio.h"
#include"stdlib.h"
int *cal(int *a,int n, int num)
{
int digit=n;//sizeof(a)/sizeof(int);
int *result=a;
int *b=(int *)calloc(digit+1,sizeof(int));
for(int i=0;i<digit;i++)
{
b[i+1]=(result[i]*num+b[i])/10;
result[i]=(result[i]*num+b[i])%10;
}
if(b[digit]>=1)
{
int *c=result;
digit++;
result=(int *)malloc(sizeof(int)*digit);
for(int two=0;two<digit-1;two++)
result[two]=c[two];
result[digit-1]=b[digit-1];
}
free(b);
return result;
}
int main()
{
int a[4]={1,2,2,1};
int *d=cal(a,4,4);
for(int three=0;three<4;three++)
printf("%d",d[three]);
}