数组面试题--数组求和
生活随笔
收集整理的這篇文章主要介紹了
数组面试题--数组求和
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目描述:給定一個(gè)數(shù)組,實(shí)現(xiàn)函數(shù)用一行代碼返回這個(gè)數(shù)組的和
思路:遞歸即可
1 #include <iostream> 2 #include <queue> 3 #include <climits> 4 #include <algorithm> 5 #include <memory.h> 6 #include <stdio.h> 7 using namespace std; 8 9 int fun(vector<int> a,int n) 10 { 11 return (n==0)?0:a[n-1]+fun(a,n-1); 12 } 13 14 int main() 15 { 16 vector<int> a; 17 a.push_back(1); 18 a.push_back(2); 19 a.push_back(3); 20 cout<<fun(a,3); 21 return 0; 22 }?
轉(zhuǎn)載于:https://www.cnblogs.com/cane/p/3808753.html
總結(jié)
以上是生活随笔為你收集整理的数组面试题--数组求和的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: received packet with
- 下一篇: Oracle中的USEREVN()