
不写这个可以吗?
程序代码:#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
string add(string a, string b)
{
int i=a.length (), j=0, k=b.length ();
string c="";
while (i || j || k)
{
if (i)
{
j = j + a[i - 1] - '0';
i--;
}
if (k)
{
j = j + b[k - 1] - '0';
k--;
}
c = (char)(j % 10 + '0') + c;
j /= 10;
}
return c;
}
string mult(string a, int b)
{
int i, j=0;
string c="";
for (i = a.length(); i; i--)
{
j = b * (a[i - 1] - '0') + j;
c = (char)(j % 10 + '0')+c;
j /= 10;
}
if (j)c = char(j + '0') + c;
return c;
}
int main()
{
string a, b, c, d;
int i, j, l;
cin >> a >> b;
l = a.length() + b.length() + 1;
cout << setw(l) << a << endl << "*" << setw(l - 1) << b << endl;
for (i = 0; i < l; i++)cout << "-";
cout << endl;
for (i = b.length(); i; i--)
{
d = mult(a, (int)(b[i - 1] - '0'));
cout << setw(l + i - b.length()) << d << endl;
for (j = 0; j < b.length() - i; j++)d = d + '0';
c = add(c, d);
}
for (i = 0; i < l; i++)cout << "-";
cout << endl << setw(l) << c << endl;
return 0;
}
程序代码:
#include <iostream>
#include<iomanip>
using namespace std;
int main()
{
int a, b;
cout <<"请输入一个数回车后再输入一个数:\n";
cin >> a >> b;
system("cls");
cout <<a<<"+"<<b<<"的竖式计算过程如下:\n\n";
std::cout << setw(10)<<a<<"\n";
cout << setw(2 )<< "+" << setw(8) << b<<endl;
cout << "-----------\n";
cout << setw(10) << a + b;
while (true)
{
;
}
return 0;
}
