我尝试将第一个数字存储在数组中,然后将该数字的每个数字与第二个数字相乘,并将进位单独存储在临时变量中。
#include<stdio.h>
int main()
{
int i=0,j=0,b,temp,a,count=0,arr[1000];
scanf("%d",&a);
scanf("%d",&b);
while(a!=0)
{
arr[++i]=a%10;
a=a/10;
count++;
}
temp=0;
for(j=0;j<count;j++)
{
temp=arr[j]*b+temp;
arr[j]=temp%10;
temp=temp/10;
}
while(temp>0)
{
arr[++j]=temp%10;
count++;
temp=temp/10;
}
for(i=count;i>0;i++)
printf("%d",arr[i]);
return 0;
}
最佳答案
通过使用表达式arr[++i]
,您首先递增i
,然后然后设置数组的值。因此,arr[0]
的值未定义。
关于c - 这段将两个数字相乘的代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28124773/