当前位置:网站首页>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;
}边栏推荐
- Before job hopping, Jin San made up the interview questions. Jin San successfully landed at Tencent and got a 30K test offer
- ASCII code comparison table
- Mxnet record IO details
- Teambition 协作应用心得分享|社区征文
- Lua pattern matching
- Data visualization diagram microblog forwarding diagram
- Transaction code qs28 of SAP QM preliminary level
- Integrated monitoring solution for power environment of small and medium-sized computer rooms
- Access control system based on RFID
- Research Report on market supply and demand and strategy of China's hydraulic hammer industry
猜你喜欢

Successful transition from self-study test halfway, 10K for the first test

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?

Structure knowledge points all in

Leetcode: 210. Programme II

torch. nn. Linear() function

My way of programming

Design and practice of Hudi bucket index in byte skipping

新品发布丨竣达智能综合环境监测终端

#141 Linked List Cycle

Algorinote_ 2_ Main theorem and Akra bazzi theorem
随机推荐
JS deep and shallow copy
What's a good gift for the goddess Festival? Gift recommendation for the goddess Festival on March 8
HR SaaS unicorn is about to emerge. Will the employee experience be the next explosive point?
What are the barriers that Huawei terminals need to cross if they want to rely on the intelligent turnover of the whole house?
Nexus3 build local warehouse
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
实现从字符串中删除某个字符操作
String Basics
机器学习资料汇总
Inrelease: the following signature cannot be verified because there is no public key: no_ PUBKEY EB3E94ADBE1229CF
Image processing 12- image linear blending
leetcode:207. 课程表
指针与数组&指针与const&结构体与const
Introduction to the characteristics of balancer decentralized exchange market capitalization robot
Select sort
JS中如何实现重载
#886 Possible Bipartition
How to determine the sample size of an inspection lot in SAP QM's initial sampling strategy?
Scatter in pytorch_ () function
Before job hopping, Jin San made up the interview questions. Jin San successfully landed at Tencent and got a 30K test offer