文章
25
粉丝
364
获赞
8
访问
219.2k
模拟乘法
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define max 10001
typedef struct
{
char num[max]; //从低位到高位存储
int n; //有多少位
} BigInteger;
//对调位置,使按低位到高位存储
void Reverse(BigInteger *BI)
{
char tmp;
for (int i = 0; i < BI->n; i++)
{
BI->num[i] -= '0'; //化为整形
}
for (int i = 0; i < BI->n / 2; i++)
{
tmp = BI->num[i];
BI->num[i] = BI->num[BI->n - i - 1];
BI->num[BI->n - i - 1] = tmp;
}
return;
}
//相乘的结果存放在multiplicand
void Multiply(BigInteger *multiplicand, BigInteger *multiplier, BigInteger *product)
{
unsigned char flag; //进位标志
unsigned char res;
unsigned char buff[101];//存放中间运算结果
int cnt;
//初始化
product->n = multiplicand->n - 1;
memset(product->num, 0, product->n);
//做模拟乘法
for (int i = 0, j; i < multiplier->n;...
登录后发布评论
暂无评论,来抢沙发