当前位置:网站首页>求解一维数组前缀和
求解一维数组前缀和
2022-06-12 21:01:00 【又秃又弱】
题意:
1 2 3 4 5
输出:1 1+2=3 3+3=6 6+4=10 10+5=15(输出的为前几个数之和)
代码求解:
#include<stdio.h>
int main()
{
//法一:重新扩展了内存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);
}
//法二:在元素组内更替
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;
}边栏推荐
- What are the barriers that Huawei terminals need to cross if they want to rely on the intelligent turnover of the whole house?
- EU officially released the data act, Ukraine was attacked by DDoS again, kitchen appliance giant Meiya was attacked, internal data leakage network security weekly
- #141 Linked List Cycle
- Mxnet record IO details
- 最简单ALV模板
- Cv2.lut() (populates the output array with values from the lookup table)
- My way of programming
- Algorinote_2_主定理与 Akra-Bazzi 定理
- Circularly insert one excel column and the sum of multiple columns
- #113 Path Sum II
猜你喜欢

Solution of multi machine room dynamic loop status network touch screen monitoring

shell语言

What's a good gift for the goddess Festival? Gift recommendation for the goddess Festival on March 8

typeScript的定义类型:不能将类型“Timeout”分配给类型“number”;

#141 Linked List Cycle

2022年春招,测试工程师全套面试攻略,一篇吃透全部技术栈(全是干货)

What are the disadvantages of bone conduction earphones? Analysis of advantages and disadvantages of bone conduction earphones

没有学历,自学软件测试,找到一份月入过万的测试工作真的有可能吗?

Data visualization - histogram

lintcode:127 · 拓扑排序
随机推荐
在同花顺开户安全么,买股票怎么网上开户
Introduction to the characteristics of building a balancer decentralized exchange market capitalization robot
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?
What are the barriers that Huawei terminals need to cross if they want to rely on the intelligent turnover of the whole house?
#981 Time Based Key-Value Store
Understanding of closures
JSP中的监听器
Composer version degradation
Li Mu [practical machine learning] 1.4 data annotation
Solution of multi machine room dynamic loop status network touch screen monitoring
leetcode:207. 课程表
Research Report on market supply and demand and strategy of China's hydraulic injection molding machine industry
Understanding of functions
China hydraulic cylinder linear position sensor market trend report, technical dynamic innovation and market forecast
Data visualization diagram microblog forwarding diagram
Algorinote_ 2_ Main theorem and Akra bazzi theorem
#141 Linked List Cycle
Social metauniverse: start from redefining yourself
SAP WM preliminary transaction code lx29 - list of fixed storage bins
Foreign brands become a thing of the past? What are the key words of the TV industry in 2022?