fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int countSheep(bool arr[], int n) {
  5. int count = 0;
  6. for (int i = 0; i < n; i++) {
  7. if (arr[i] == true)
  8. count++;
  9. }
  10. return count;
  11. }
  12.  
  13. int main() {
  14. bool sheep[] = {
  15. true,true,true,false,true,true,true,true,
  16. true,false,true,false,true,false,false,true,
  17. true,true,true,true,false,false,true,true
  18. };
  19.  
  20. int n = sizeof(sheep) / sizeof(sheep[0]);
  21. cout << countSheep(sheep, n);
  22. return 0;
  23. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
17