Advertisement
Fahim_7861

cumulative sum

Feb 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  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. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement