代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
两个大整数的乘法
作者:
/ 发布于
2014/5/22
/
540
这只是两个大整数的乘法,加法,减法应不成问题,你可参照下面的程序 要是除法的话,可以用数值分析里的牛顿逼近法
/*这只是两个大整数的乘法,加法,减法应不成问题,你可参照下面的程序 要是除法的话,可以用数值分析里的牛顿逼近法*/ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Question: * * How to calculate two integers each one has forty bit. * * Algorithm: * * Declare two arrays suppose to be array A and B to storage * * the two integers just as a intacter singly. * * Get the first number from array B,then use it to multiply * * the number of array A singly. Declare another array C to * * storage the value when multiplying. * * Thinking about the carrying bits. * * Thinking: * * Can you use the Linear_List to do this? * * If they are two floating numbers,so how to do it? * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <stdio.h> #include <assert.h> #include <stdlib.h> #include <conio.h> //To calculate two 40 bits integers multiply,change 10 to 40 #define THE_ARR_A_SIZE 10 #define ARR_B_SIZE THE_ARR_A_SIZE #define ARR_C_SIZE (THE_ARR_A_SIZE + ARR_B_SIZE) void main(void); void Multiply( short *, short *, short *, short, short); void Carrying( short *c, short); void main(void) { short A[THE_ARR_A_SIZE] = {9, 9, 9, 9, 9, 9, 9, 9, 9, 9}; // 10 short B[ARR_B_SIZE] = {9, 9, 9, 9, 9, 9, 9, 9, 9, 9}; short C[ARR_C_SIZE]; short i = 0; for ( NULL; i < ARR_C_SIZE; i++) { *(C+i) = 0; } Multiply(A, B, C, THE_ARR_A_SIZE, ARR_B_SIZE); Carrying(C, ARR_C_SIZE); printf("\\nThe Result is: "); i = 0; if (C[0] == 0) ++i; //To delete the primacy zero for ( NULL; i < ARR_C_SIZE; i++) { printf("%d", C[i]); } getch(); printf("\\n"); } /* * NOTICE: * The Array C is not initialed,you should do that. Here * the array is supposed to be filled zero. * Algorithm: * */ void Multiply( short A[], short B[], short C[], short A_size, short B_size) { short i = 0, j = 0, k = 1; // Assigned k to 1 to leave C[0] //be null to storage the carrying. for (j = 0; j<B_size; j++) { for (i = 0; i<A_size; i++) { C[k] += B[j] * A[i]; k++; } k = 2; k = k + j; } } // To solve the carrying . void Carrying(short C[],short C_size) { short i, tens_place = 0, units_order = 0; short temp = 0, end_arr; end_arr = C_size-1; for (i = end_arr; i >= 0; i--) { temp = C[i]; if (C[i] > 9) { tens_place = temp / 10; units_order = temp % 10; C[i-1] += tens_place; C[i] = units_order; } } }
试试其它关键字
大整数的乘法
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
贡献的其它代码
Label
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3