Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- vector <int> v;
- # define ll long long
- ll indx(int n)
- {
- if ( n==0 ) return v[0];
- ll ans=v[n]+v[indx(n-1)];
- return ans;
- }
- int main()
- {
- cout<<"Enter number of elements : ";
- int n;
- cin>>n;
- v=vector <int> (n, 1);
- for ( int i=0 ; i<n ; i++) cin>>v[i];
- ll ans=indx(n-1);
- cout<<"Sum of all elements of the array : "<<ans;
- return 0;
- }
Add Comment
Please, Sign In to add comment