daily pastebin goal
49%
SHARE
TWEET

cumulative sum

Fahim_7861 Feb 18th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int n;
  7.  
  8.     cin>>n;
  9.  
  10.     int ara[n+1],sum[n+1];
  11.  
  12.     int pre=0;
  13.  
  14.     for(int i=0; i<n; i++)
  15.     {
  16.         cin>>ara[i];
  17.  
  18.         sum[i]=ara[i]+pre;
  19.  
  20.         pre=sum[i];
  21.     }
  22.  
  23.     for(int i=0; i<n; i++)
  24.         cout<<sum[i]<<" ";
  25. }
  26.  
  27. /*
  28. 5
  29. 32 45 2 3 4
  30. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top