fork download
  1. #include <iostream>
  2. #include<vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. vector<int> a={2,7,4,8,9,1,6};
  8. int k=9;
  9. int count=0;
  10. for(int i=0;i<a.size();i++) {
  11. int sum=0;
  12. for(int j=i;j<a.size();j++) {
  13. sum+=a[j];
  14. if(sum==k) {
  15. count++;
  16. }
  17. }
  18. }
  19. cout<<count<<endl;
  20. return 0;
  21. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
2