DSA/Lab_2/Lab_2_mem.c

35 lines
791 B
C
Raw Permalink Normal View History

2024-03-09 17:32:59 +02:00
#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;
}