Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iostream>
- #include <vector>
- int main() {
- short negative = 0, pos = 0;
- double* array_all = (double*)malloc(12 * sizeof(double)); //all elements
- double* array_second = NULL; //elements after the second negative
- for(int i = 0; i < 12; ++i) {
- double tmp = 4.4 * std::tan(2.1 * (i + 1)) + (12.16 * std::pow(i + 1, 3.0) + std::cos(2.0 * (i + 1)))
- / (3.0 * (2.0 * std::exp(1.1 * (i + 1)) - 0.6));
- array_all[i] = tmp;
- if(tmp < 0) ++negative;
- if(negative >= 2) {
- if(array_second == NULL) {
- pos = i;
- array_second = (double*)malloc((12 - pos + 1) * sizeof(double));
- }
- array_second[i - pos] = tmp;
- }
- }
- //additional code here
- free(array_all);
- free(array_second);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement