当前位置:网站首页>Solve one-dimensional array prefix sum
Solve one-dimensional array prefix sum
2022-06-12 21:05:00 【Bald and weak】
The question :
1 2 3 4 5
Output :1 1+2=3 3+3=6 6+4=10 10+5=15( The output is the sum of the first few numbers )
Code solving :
#include<stdio.h>
int main()
{
// Law 1 : Re expanded memory result
int arr[]={1,2,3,4,5};
int len=sizeof(arr)/sizeof(arr[0]);
int result=0;
for(int i=0;i<len;i++)
{
result+=arr[i];
printf("%d",result);
}
// Law two : Replace within an element group
int arr[]={1,2,3,4,5};
int len=sizeof(arr)/sizeof(arr[0]);
for(int i=1;i<len;i++)
{
arr[i]+=arr[i+1];
}
for(int i=0;i<len;i++)
{
printf("%d",arr[i]);
}
return 0;
}边栏推荐
- At the same time, do the test. Others have been paid 20W a year. Why are you still working hard to reach 10K a month?
- Introduction to scala basic grammar (III) various operators in Scala
- 插入排序
- 居家办公期间如何提升沟通效率|社区征文
- Integrated monitoring solution for power environment of small and medium-sized computer rooms
- Before job hopping, Jin San made up the interview questions. Jin San successfully landed at Tencent and got a 30K test offer
- Data visualization - histogram
- Inrelease: the following signature cannot be verified because there is no public key: no_ PUBKEY EB3E94ADBE1229CF
- Pytorch how to set random number seed to make the result repeatable
- JS deep and shallow copy
猜你喜欢

Vs2017 environmental issues

The year of the outbreak of financial innovation! All dtinsight products of kangaroo cloud data stack have passed the special test of Xinchuang of ICT Institute

Is it really possible to find a testing job with a monthly income of more than 10000 without a degree and self-study software testing?

#113 Path Sum II
![Li Mu [practical machine learning] 1.4 data annotation](/img/e4/2593b1dec04476a9cc3b4af94dc189.jpg)
Li Mu [practical machine learning] 1.4 data annotation

结构体知识点all in

Listener in JSP

How do testers plan for their future? To achieve 25K in 2 years?

Introduction to the characteristics of balancer decentralized exchange market capitalization robot

Lake shore PT-100 platinum resistance temperature sensor
随机推荐
Select sort
New product release Junda intelligent integrated environmental monitoring terminal
Research Report on hydraulic injection machine industry - market status analysis and development prospect forecast
Market trend report, technical innovation and market forecast of hydraulic chain hoist in China
一级指针&二级指针知识点梳理
At the same time, do the test. Others have been paid 20W a year. Why are you still working hard to reach 10K a month?
二分查找
循环插入excel某一列,以及多列之和
Data visualization - histogram
选择排序
Gather function in pytorch_
Research Report on hydraulic solenoid valve industry - market status analysis and development prospect forecast
JS中如何实现重载
remote: Support for password authentication was removed on August 13, 2021
Solution of multi machine room dynamic loop status network touch screen monitoring
Introduction to the characteristics of balancer decentralized exchange market capitalization robot
Inrelease: the following signature cannot be verified because there is no public key: no_ PUBKEY EB3E94ADBE1229CF
Data visualization diagram microblog forwarding diagram
#886 Possible Bipartition
Compréhension préliminaire des expressions régulières cognitives (regex)