竖式计算来喽

#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
int main() {
    system("color BA");
    cout<<"竖式计算机已启动.";
    Sleep(500);
    system("cls");
    cout<<"竖式计算机已启动..";
    Sleep(500);
    system("cls");
    cout<<"竖式计算机已启动...";
    Sleep(500);
    system("cls");
    cout<<"竖式计算机已启动.";
    Sleep(500);
    system("cls");
    cout<<"竖式计算机已启动..";
    Sleep(500);
    system("cls");
    cout<<"竖式计算机已启动...";
    Sleep(500);
    system("cls"); 
    cout<<"竖式计算机已启动.";
    Sleep(500);
    system("cls");
    cout<<"竖式计算机已启动..";
    Sleep(500);
    system("cls");
    cout<<"竖式计算机已启动...";
    Sleep(500);
    system("cls");
    int a;
    for(a=0;a<=0;a=a+0){
    cout<<"输两个十位数吧!!!";
    Sleep(2000);
    system("cls");
        int b,c;
        cin>>b>>c;
        system("cls");
        if(b>=10&&b<=99&&c>=10&&c<=99){
        if(b%10!=0&&c%10!=0){
        cout<<b<<"*"<<c<<"="<<b*c<<endl;
        cout<<"----竖式----"<<endl;
        cout<<" "<<b<<endl;
        cout<<"*"<<c<<endl;
        cout<<"------"<<endl;
        cout<<" "<<b*(c%10)<<endl; 
        cout<<b*(c/10)<<""<<endl;
        cout<<"------"<<endl;
        cout<<b*c<<endl;
        Sleep(8000);
        system("cls");    
        }if(b%10==0&&c%10!=0){
        cout<<b<<"*"<<c<<"="<<b*c<<endl;
        cout<<"----竖式----"<<endl;
        cout<<" "<<c<<endl;
        cout<<"* "<<b<<endl;
        cout<<"------"<<endl;
        cout<<b*c<<endl;
        Sleep(5000);
        system("cls");
        }if(c%10==0&&b%10!=0){
        cout<<b<<"*"<<c<<"="<<b*c<<endl;
        cout<<"----竖式----"<<endl;
        cout<<" "<<b<<endl;
        cout<<"* "<<c<<endl;
        cout<<"------"<<endl;
        cout<<b*c<<endl;
        Sleep(5000);
        system("cls");
        }if(b%10==0&&c%10==0){
            cout<<b<<"*"<<c<<"="<<b*c<<endl;
            cout<<"---此题无竖式---"<<endl;
            Sleep(2000);
             system("cls");
        }
            
        }else{
            cout<<"你干嘛~啊"<<endl;
            Sleep(2000);
            system("cls"); 
        }
        
        
    }  
    return 0;
}
 

### 计算方法详解 计算是一种基础的手动算术运算方,在编程中模拟这种算法可以加深对基本数学操作的理解。对于大数相乘或者特定场景下的数值处理非常有用。 #### 模拟乘法的核心概念 在不将字符串转换成整型的情况下实现两数相乘,关键是模仿手工完成多位数乘法的过程: - 将每一位上的数字单独取出并与另一个完整的被乘数逐位相乘; - 记录每次部分积的结果并考虑位置偏移(即错开相应的位置),最终累加以获得总和作为最终结果[^1]。 #### Python代码实例展示如何模拟乘法 下面是一个具体的例子来说明怎样通过Python程序实现上述逻辑: ```python def multiply_strings(num1, num2): if num1 == "0" or num2 == "0": return "0" result = [0] * (len(num1) + len(num2)) for i in range(len(num1)-1, -1, -1): carry = 0 for j in range(len(num2)-1, -1, -1): temp_sum = int(num1[i]) * int(num2[j]) + result[i+j+1] + carry result[i+j+1] = temp_sum % 10 carry = temp_sum // 10 result[i] += carry # Convert list to string and remove leading zeros. result_str = ''.join(map(str, result)).lstrip("0") return result_str if result_str != "" else "0" print(multiply_strings("123", "456")) # 输出:"56088" ``` 此函数接收两个由字符组成的非负整数串`num1`和`num2`,返回它们的乘积累计值同样是以字符串的形给出。这里采用逆序遍历的方来进行每位之间的相乘,并妥善管理进位情况以确保准确性[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值