Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int multiplicationOfElements(int[], int);
- int findSecondMinus(int[], int);
- int const N = 10;
- int main()
- {
- int array[N] = { 0 };
- cout << "enter the elements of array:" << endl;
- for (int i = 0; i < N; i++)
- {
- cout << "a[" << (i + 1) << "]";
- cin >> array[i];
- }
- cout << endl;
- cout << "the product is:" << multiplicationOfElements(array, findSecondMinus(array, N)) << endl;
- system("pause");
- return 0;
- }
- int multiplicationOfElements(int source[], int size)
- {
- int mult = 1, k = 0;
- for (int i = 0; i < size; i++)
- {
- mult *= source[i];
- }
- return mult;
- }
- int findSecondMinus(int source[], int size)
- {
- int index = 0,k=0;
- for (int i = 0; i < size; i++)
- {
- if (k == 2)
- {
- return index-1;
- }
- if (source[i] >= 0)
- {
- index++;
- }
- else
- {
- index++;
- k++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement