Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int multiplicationOfElements(int[], int);
  6. int findSecondMinus(int[], int);
  7.  
  8. int const N = 10;
  9.  
  10. int main()
  11. {
  12.     int array[N] = { 0 };
  13.     cout << "enter the elements of array:" << endl;
  14.     for (int i = 0; i < N; i++)
  15.     {
  16.         cout << "a[" << (i + 1) << "]";
  17.         cin >> array[i];
  18.     }
  19.     cout << endl;
  20.     cout << "the product is:" << multiplicationOfElements(array, findSecondMinus(array, N)) << endl;
  21.  
  22.     system("pause");
  23.     return 0;
  24. }
  25. int multiplicationOfElements(int source[], int size)
  26. {
  27.     int mult = 1, k = 0;
  28.     for (int i = 0; i < size; i++)
  29.     {
  30.         mult *= source[i];
  31.     }
  32.     return mult;
  33. }
  34. int findSecondMinus(int source[], int size)
  35. {
  36.     int index = 0,k=0;
  37.     for (int i = 0; i < size; i++)
  38.     {
  39.         if (k == 2)
  40.         {
  41.             return index-1;
  42.         }
  43.         if (source[i] >= 0)
  44.         {
  45.             index++;
  46.         }
  47.         else
  48.         {
  49.             index++;
  50.             k++;
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement