#include <iostream>
#include <cmath>
using namespace std;
int wei(int num)//统计位数
{
int count = 0;
while (num != 0)
{
num = num / 10;
count++;
}
return count;
}
void main()
{
int num1, num2;
cout << "Input two number:";
cin >> num1;
cin >> num2;
int a1[5];
int b1[5];
int count1 = wei(num1);
cout << "count1 "<<count1 << endl;
int count2 = wei(num2);
cout << "count2 "<<count2 << endl;
int temp1, power1;
for (int i = 1; i <=count1; i++)
{
power1 = pow(10.0, count1 - i); //幂函数
temp1 = num1 / power1;
a1[i] = temp1;
cout << a1[i] << " ";
num1 = num1 % power1;
}
cout << endl;
int temp2, power2;
for (int i = 1; i <= count2; i++)
{
power2 = pow(10.0, count2 - i); //幂函数
temp2 = num2 / power2;
b1[i] = temp2;
cout << b1[i]<< " ";
num2 = num2 % power2;
}
cout << endl;
int sum = 0;
for (int i = 0; i <= count1; i++)
{
for (int j = 0; j <= count2; j++)
{
sum = a1[i] * b1[j] + sum;
//cout << sum << endl;
}
}
cout << sum << endl;
system("pause");
}
联系客服