[ create a new paste ] login | about

Link: http://codepad.org/XfZmmcME    [ raw code | output | fork ]

C++, pasted on Jan 19:
#include <iostream>
#include <numeric>

bool Greater5OrLessEqual3(int n)
{
  return n > 5 || n <=3;
}

struct Multiplier : binary_function<int, int, bool> {
  int operator()(int left, int right)
  { 
    return (right % 2 != 0)? left * right : left;
  }
};

int main()
{
  int       arr[] = {1, 2, 3, 4, 5, 6};
  const int size  = sizeof(arr) / sizeof(arr[0]);

  std::cout << std::accumulate(arr, arr + size, 1, Multiplier())      << std::endl;
  std::cout << std::count_if  (arr, arr + size, Greater5OrLessEqual3) << std::endl;

  return 0;
}


Output:
1
2
15
4


Create a new paste based on this one


Comments: