35 lines
791 B
C
35 lines
791 B
C
|
#include <stdio.h>
|
||
|
#include <math.h>
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
int operation_counter = 0;
|
||
|
|
||
|
int n;
|
||
|
|
||
|
printf("Input n (must be a natural number): ");
|
||
|
scanf("%d", &n);
|
||
|
|
||
|
double result = 0;
|
||
|
|
||
|
double denominator = 1;
|
||
|
double power_of_four = 1;
|
||
|
|
||
|
operation_counter += 3; // power_of_four = 1, denominator = 1, result = 0
|
||
|
|
||
|
operation_counter += 2; // for loop
|
||
|
for (int i = 1; i <= n; i++)
|
||
|
{
|
||
|
denominator *= i + cos(i);
|
||
|
power_of_four *= 4;
|
||
|
|
||
|
result += (power_of_four - i) / denominator;
|
||
|
operation_counter += 9; // result += (power_of_four - i) / denominator, power_of_four *= 4, denominator *= i + cos(i), i <= n, i++
|
||
|
}
|
||
|
|
||
|
printf("Result = %.7f\n", result);
|
||
|
printf("Number of operations = %d\n", operation_counter);
|
||
|
|
||
|
return 0;
|
||
|
}
|