求大数(用数组存放)
来源:互联网 发布:js加密压缩后怎么调用 编辑:程序博客网 时间:2024/05/18 21:08
#include<stdio.h>
#include<stdlib.h>
//****************************
//大数运算
//1+2+4+8+.......+2^100 =
//思路:用足够大的数组存放结果
//求2^101-1
//****************************
#define N 1000 //设置足够大的数组存放位数
int res[N];
int bigNumber(int num)
{
int flag=0; //设置进位
int total=1; //返回总位数
int count;
int i,temp;
res[0] = 1;
for(i=0;i<num;i++)
{
for(count=0;count<total;count++)
{
temp = (res[count]<<1)+ flag; //每个位数与2相乘
res[count] = temp%10;
flag = temp/10;
}
while(flag) //有进位
{
res[total] = flag%10; //flag有可能大于10?
flag = flag/10;
total++; //总位数+1
}//for count
}//for i
res[0] -= 1;
return total; //返回总位数
}
int main()
{
int m_total;
int i;
int m_num = 101;
printf("2^101-1 = ");
m_total = bigNumber(101);
for(i=m_total-1;i>=0;i--)
printf("%d",res);
printf("/n");
system("pause");
return 0;
}
- 求大数(用数组存放)
- Java实现大数的阶乘(数组存放数据)
- c++实现大数的加减乘运算(数组存放)
- 求大数的阶乘方法(数组)
- 求1000!(通过数组模拟大数)
- 数组法求大数阶乘
- 求数组中的第三大数
- 用冒泡算法求数组的第N大数
- 求大数阶乘(存储在数组中)
- 求数组中第二大数(后续求第K大)
- 求一个数组中的最大次大数
- 求一个数组中第二大数...
- 求数组中第K大数
- 求数组的第k大数
- 用数组存放书本信息
- C++用数组存放数据
- 数组存放
- 大数求余(String求余)
- Google搜索指令大全(收藏)
- 组合数字
- 游戏人生
- django+apache配置网站的robots.txt和sitemaps等理静态文件
- Codeforces Beta Round #35 (Div. 2) C (BFS~水~)
- 求大数(用数组存放)
- ruby元编程
- 欢迎下载
- centos 实现登录系统时有选择的进入文字模式(3)图形模式(5)的menu.lst设置
- Linux网络
- 步进电机
- 在程序增加多语言功能
- [经验总结]VC++内存泄漏定位与调试
- magento -- 列表页显示产品属性值的几种调用方式