帮忙用cpp写一个高精度除法的项目,不用vector,用string,考虑余数,输出商和余数。
时间: 2023-02-12 16:48:18 浏览: 110
下面是一个用 C++ 编写的高精度除法的简单示例,使用了 string 类型并考虑了余数:
```
#include <iostream>
#include <string>
using namespace std;
string divide(string dividend, int divisor, int &remainder) {
string quotient = "";
remainder = 0;
for (int i = 0; i < dividend.length(); i++) {
remainder = remainder * 10 + (dividend[i] - '0');
if (remainder < divisor) {
quotient += '0';
continue;
}
quotient += (remainder / divisor) + '0';
remainder = remainder % divisor;
}
return quotient;
}
int main() {
string dividend;
int divisor;
int remainder;
cin >> dividend >> divisor;
string quotient = divide(dividend, divisor, remainder);
cout << "商: " << quotient << endl;
cout << "余数: " << remainder << endl;
return 0;
}
```
这个程序会输入被除数和除数,并输出商和余数。
阅读全文