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