#include #include using namespace std; int product(int n, ...) { va_list L; va_start(L, n); int r = 1; for (int i = 1; i <= n; i += 1) r *= va_arg(L, int); va_end(L); return r; } int main() { cout << "2 3 4 5: " << product(4, 2, 3, 4, 5) << "\n"; cout << "8 9: " << product(2, 8, 9) << "\n"; cout << "2 3 4 5 6 7: " << product(6, 2, 3, 4, 5, 6, 7) << "\n"; cout << ": " << product(0) << "\n"; } /* it will print 2 3 4 5: 120 8 9: 72 2 3 4 5 6 7: 5040 : 1 */