Advertisement
kamos

Untitled

Oct 23rd, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. int main() {
  6.     short negative = 0, pos = 0;
  7.     double* array_all = (double*)malloc(12 * sizeof(double));   //all elements
  8.     double* array_second = NULL;                    //elements after the second negative
  9.     for(int i = 0; i < 12; ++i) {
  10.         double tmp = 4.4 * std::tan(2.1 * (i + 1)) + (12.16 * std::pow(i + 1, 3.0) + std::cos(2.0 * (i + 1)))
  11.             / (3.0 * (2.0 * std::exp(1.1 * (i + 1)) - 0.6));
  12.         array_all[i] = tmp;
  13.         if(tmp < 0) ++negative;
  14.         if(negative >= 2) {
  15.             if(array_second == NULL) {
  16.                 pos = i;
  17.                 array_second = (double*)malloc((12 - pos + 1) * sizeof(double));
  18.             }
  19.             array_second[i - pos] = tmp;
  20.         }
  21.     }
  22.     //additional code here
  23.    
  24.     free(array_all);
  25.     free(array_second);
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement