- 1
- 0
- 约5.24千字
- 约 15页
- 2017-10-06 发布于河南
- 举报
大整数的一些算法(Some algorithms for large integers)
大整数的一些算法(Some algorithms for large integers)
Some large integer algorithm / write, online can be found, but not complete
* program, and then write a relatively complete procedure, issued on the Blog
* /
#include stdio.h
#define MAXINT 1000
Int compare (int, a[], int, b[]);
Int bigplus (int, a[], int, b[], int, c[]);
Int bigsub (int, a[], int, b[], int, c[]);
Int bigmult (int, a[], unsigned, int, B, int, c[]);
Int bigmult2 (int, a[], int, b[], int, c[]);
Int, bigdiv (int, a[], unsigned, int, B, int, c[], int, *d);
Int, bigdiv2 (int, a[], int, b[], int, c[], int, d[]);
Int main (int, argc, char, *argv[])
{
Int a[MAXINT]={10,5,4,6,5,4,3,2,1,1,1}; / / or multiplicand divisor
Int b[MAXINT]={7,7,6,5,4,3,2,1}; / / multiplier or divisor
Int c[MAXINT], d[MAXINT]; //c[] store provider; d[] stores remainder
Int div=1234; / / small multiplier or small divisor
Int k=0;
Int *res=k; / / pointer small integer remainder
Bigplus (a, B, C);
Bigsub (a, B, C);
Bigmult (a, div, C);
Bigmult2 (a, B, C);
Bigdiv (a, div, C, res);
Bigdiv2 (a, B, C, D);
Getchar ();
Return 0;
}
Int compare (int a[], int b[]) / / relatively large integers
{
Int i;
If (a[0]b[0]) return 1; / / compare a, B number determines the return value
Else if (a[0]b[0]) return -1;
Comparison of else / / equal number of
{
I=a[0];
While (a[i]==b[i]) / bit comparison
I--;
If (i==0) return 0;
Else if (a[i]b[i]) return 1;
Else return -1;
}
}
Int bigplus (int a[], int b[], int c[]) / / large integer addition
{
Int, I, len;
Len= (a[0]b[0]: a[0]: b[0]); //a[0] b[0] holds the array length, and Len is the longer one
For (i=0; iMAXINT; i++) / / array 0
C[i]=0;
For (i=1; i=len; / / i++) was calculated for each bit value
{
C[i]+= (a[i]+b[i]);
If (c[i]=10)
{
C[i]-=10; / / take a bit more than 10
C[i+1]++; / / 1 high
}
}
If (c[i+1]0) len++;
C[0]=len; //c[0] save the actual length of the result array
Printf (Big integers add:;
For (i=len; i=1; i--)
Printf (%d, c[i]); / / print results
Printf (\n;
Return 0;
}
Int bigsub (int a[], int b[], in
您可能关注的文档
- 商业银行表外业务会计处理(Accounting treatment of off balance sheet business of commercial banks).doc
- 商务周刊12年无一笔呆坏账的民间借贷神话(Business Week 12 years without a bad debt of private lending myth).doc
- 商务英语(bec)常用精选句型100句(Business English (BEC) commonly used sentence patterns 100 sentences).doc
- 商务谈判开局阶段(Opening stage of business negotiations).doc
- 商品房销售面积的测量与计算办法(Measurement and calculation method of commercial housing sales area).doc
- 商品拜物教(Commodity fetishism).doc
- 商品鱼饵配方(经典合集)(Recipe for commercial bait (Classic Collection)).doc
- 商场的消防(Fire in shopping malls).doc
- 商务宴请礼仪大全(Complete etiquette for business banquets).doc
- 商学电影(Business films).doc
- 2025-2026学年天津市和平区高三(上)期末数学试卷(含解析).pdf
- 2025-2026学年云南省楚雄州高三(上)期末数学试卷(含答案).pdf
- 2025-2026学年甘肃省天水市张家川实验中学高三(上)期末数学试卷(含答案).docx
- 2025-2026学年福建省厦门市松柏中学高二(上)期末数学试卷(含答案).docx
- 2025-2026学年广西钦州市高一(上)期末物理试卷(含答案).docx
- 2025-2026学年河北省邯郸市临漳县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省石家庄二十三中七年级(上)期末历史试卷(含答案).docx
- 2025-2026学年海南省五指山市九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省唐山市玉田县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省邢台市市区九年级(上)期末化学试卷(含答案).docx
原创力文档

文档评论(0)