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. for(int j=i;j<n;j++){
  12. currSum=0;
  13. for(int k=i;k<=j;k++){
  14. currSum+=arr[k];
  15. }
  16. if(currSum==sum)
  17. count++;
  18. }
  19. }
  20. cout<<count;
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
2