c++写九九陈法表,除法表,加法以及减法表

互相学习 界面效果一般

**

陈法表

**

#include<iostream>
using namespace std;
void main()
{
	int i, j;
	for (i = 1; i <= 9; i++)
	{
		for (j = 1; j <= i; j++)
			cout << i << "*" << j << "=" << i * j << " ";
		cout << endl;
	}

	system("pause");
}

**

除法表

**

#include<iostream> 
using namespace std;
int main()
{
	int i, j;
	for (i = 1; i <= 9; i++)//行循环
	{
		for (j = 1; j <= i; j++)//列循环 (行列结合 有多少行就有多少列)
		{
			cout << i * j << "/" << j << "=" << (j * i) / j << " ";
		}
		cout << endl;
	}
	system("pause");
}

**

加法表

**

#include<iostream>
using namespace std;
void main()
{
	int i, j;
	for (i = 1; i <= 9; i++)
	{
		for (j = 1; j <= i; j++)
			cout << i << "+" << j << "=" << i + j << " ";
		cout << endl;
	}

	system("pause");
}

**

减法表:

**

#include<iostream> 
using namespace std;
int main()
{
	int i, j;
	for (i = 1; i<=9; i++)
	{
		for (j = 9; j >=i; j--)
		{
			cout << j+1 << "-" << i << "=" <<(j+1)-i<<" ";
		}
		cout << endl;
	}
	system("pause");
}
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是一个简单的高精度除法C++代码示例: ```c++ #include <iostream> #include <cstring> #include <cstdio> using namespace std; const int MAXN = 10010; // 数组的最大长度 const int BASE = 10; // 进制 struct BigInt { int len, s[MAXN]; BigInt() { memset(s, 0, sizeof(s)); len = 1; } BigInt(int num) { *this = num; } BigInt(const char* num) { *this = num; } BigInt operator = (int num) { char s[MAXN]; sprintf(s, "%d", num); *this = s; return *this; } BigInt operator = (const char* num) { memset(s, 0, sizeof(s)); len = strlen(num); for (int i = 0; i < len; i++) s[i] = num[len - 1 - i] - '0'; return *this; } string str() const { string res = ""; for (int i = 0; i < len; i++) res = (char)(s[i] + '0') + res; if (res == "") res = "0"; return res; } BigInt operator + (const BigInt& b) const { BigInt c; c.len = 0; for (int i = 0, g = 0; g || i < max(len, b.len); i++) { int x = g; if (i < len) x += s[i]; if (i < b.len) x += b.s[i]; c.s[c.len++] = x % BASE; g = x / BASE; } return c; } BigInt operator - (const BigInt& b) const { BigInt c; c.len = 0; for (int i = 0, g = 0; i < len; i++) { int x = s[i] - g; if (i < b.len) x -= b.s[i]; if (x >= 0) g = 0; else { g = 1; x += BASE; } c.s[c.len++] = x; } c.trim(); return c; } BigInt operator * (const BigInt& b) const { BigInt c; c.len = len + b.len; for (int i = 0; i < len; i++) for (int j = 0; j < b.len; j++) c.s[i + j] += s[i] * b.s[j]; for (int i = 0; i < c.len - 1; i++) { c.s[i + 1] += c.s[i] / BASE; c.s[i] %= BASE; } c.trim(); return c; } // 高精度除法 BigInt operator / (const BigInt& b) const { BigInt c; c.len = len - b.len + 1; for (int i = c.len - 1; i >= 0; i--) { BigInt t = b; if (*this < t * BigInt(BASE) * BigInt(i)) { c.s[i] = 0; continue; } int l = 0, r = BASE - 1, ans; while (l <= r) { int mid = (l + r) >> 1; if (*this >= t * BigInt(mid)) { ans = mid; l = mid + 1; } else r = mid - 1; } c.s[i] = ans; *this = *this - t * BigInt(ans); } c.trim(); return c; } // 去掉前导0 void trim() { while (len > 1 && !s[len - 1]) len--; } // 判断大小 bool operator < (const BigInt& b) const { if (len != b.len) return len < b.len; for (int i = len - 1; i >= 0; i--) if (s[i] != b.s[i]) return s[i] < b.s[i]; return false; } bool operator > (const BigInt& b) const { return b < *this; } bool operator <= (const BigInt& b) const { return !(b < *this); } bool operator >= (const BigInt& b) const { return !(*this < b); } bool operator != (const BigInt& b) const { return b < *this || *this < b; } bool operator == (const BigInt& b) const { return !(b < *this) && !(*this < b); } }; ostream& operator << (ostream& out, const BigInt& x) { out << x.str(); return out; } istream& operator >> (istream& in, BigInt& x) { string s; in >> s; x = s.c_str(); return in; } int main() { BigInt a, b, c; cin >> a >> b; c = a / b; cout << c << endl; return 0; } ``` 该代码中定义了一个结构体`BigInt`,示高精度整数。实现了加法减法、乘法和除法操作。其中,高精度除法的实现是用二分法来找出商的每一位。 使用时只需要输入两个字符串,分别示被除数和除数,然后调用`/`操作符即可得到商。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值