当前位置:网站首页>Addition of large numbers
Addition of large numbers
2022-07-27 16:23:00 【Xavier】
Algorithm is summarized : Add large numbers
We will inevitably encounter large numbers in the process of calculation , And a variable cannot be stored , So we need to use the linear table to calculate .
We can pass an example
1!+2!+3!+4!+…50!
int n,a[1000]={
0},b[1000]={
0}; // Initialize the array to zero
scanf("%d",&n);
a[0]=b[0]=1; // Take the first element as 1 Convenient for later multiplication
for(int i=2;i<=n;i++){
for(int j=0;j<100;j++)
a[j]*=i;
// stay a Calculate the factorial of each number in this array
for(int j=0;j<100;j++)
if(a[j]>9){
a[j+1]+=a[j]/10;
a[j]%=10;
}
This part is the result of calculating the factorial number of each part
for(int j=0;j<100;j++){
b[j]+=a[j];
if(b[j]>9){
b[j+1]+=b[j]/10;
b[j]%=10;
}
}
This section is to calculate the sum of each factorial result
Therefore, through the array, you can calculate large numbers so that there will be no data overflow in a single variable .
边栏推荐
- C语言程序设计(第三版)
- Flask connects to existing tables in MySQL database
- webRTC中的coturn服务安装
- JSP基础
- Time series ARIMA model
- Common problems of mobile terminal H5
- Samsung closes its last mobile phone factory in China
- 大数相加
- 4位数的随机数据
- Embedded development: tips and techniques -- seven techniques to meet the real-time deadline
猜你喜欢
随机推荐
插入word中的图片保持高dpi方法
ARIMA model selection and residuals
4-digit random data
Determine the exact type of data
Servlet basic knowledge points
google chrome revercecaptcha广告屏蔽
centos上mysql5.7主从热备设置
Openwrt new platform compilation
Coding technique - Global log switch
实现浅拷贝和深拷贝+
JMeter5.3 及以后的版本jmeter函数助手生成的字符在置灰无法复制
Delete node quickly and efficiently_ modules
JSP基础
DRF learning notes (preparation)
Paper_Book
const小结
Axure 安装图标字体元件库
大数相加
Mapreduce实例(一):WordCount
C channel simply implements the publishing and subscription of message queue









