fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int for_soe2(int A[], int n) {
  5. return 0;
  6. }
  7. int for_soe(int A[], int n) {
  8. return 0;
  9. }
  10. int for_soe1(int A[], int n) {
  11. return 0;
  12. }
  13.  
  14. int sum_of_elements(int A[], int n) {
  15. int sum = 0;
  16. while(--n) {
  17. sum += A[n];
  18. }
  19.  
  20. return sum;
  21. }
  22.  
  23. int main() {
  24. int A[] = {1, 2, 3};
  25. int n = 3;
  26.  
  27. std::pair<int (*)(int A[], int n), string> checks[] = {
  28. {for_soe2, "That's array don't have any zero elements!"},
  29. {for_soe , "The last element is zero!" },
  30. {for_soe1 , "Zero element was penultimate!" },
  31. };
  32.  
  33. for(auto const& check: checks) {
  34. if(check.first(A, n) == 0)
  35. cout << check.second << endl;
  36. }
  37.  
  38. cout << "Sum of the elements: " << sum_of_elements(A, n) << endl;
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 4188KB
stdin
Standard input is empty
stdout
That's array don't have any zero elements!
The last element is zero!
Zero element was penultimate!
Sum of the elements: 5