fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int arr[]= {1,0,1,2,10,5};
  6. int n=sizeof(arr)/sizeof(arr[0]);
  7. int sum=3;
  8. int currSum;
  9. int count=0;
  10. for(int i=0;i<n;i++){
  11. currSum=0;
  12. for(int j=i;j<n;j++){
  13. currSum+=arr[j];
  14. if(currSum==sum)
  15. count++;
  16. }
  17. }
  18. cout<<count;
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
2