fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. int countNegative(int testArray[],int n);
  6.  
  7. int main(){
  8. int testArray[] = {-2,0,44,12,-45,17,934,-21,67,88,91,1,0,6};
  9. int n = 14;
  10.  
  11. cout << countNegative(testArray,n);
  12.  
  13. //system("PAUSE");
  14. //EXIT_SUCCESS;
  15. return 0;
  16. }
  17.  
  18. int countNegative(int testArray[],int n){
  19. int total_negatives = 0;
  20. for(int i=0; i<n; i++){
  21. if(testArray[i]<0){
  22. total_negatives++;
  23. }
  24. }
  25. if (total_negatives == 0) cout << "No Negative numbers\n";
  26. return total_negatives;
  27. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
3