Professional Documents
Culture Documents
Виконав: Перевірила:
Студент групи ІМ-24 Молчанова А. А.
Дідур Вадим Сергійович
номер у списку групи: 3
Київ 20
1. Задане натуральне число n. Вирахувати значення заданої
формули за варіантом
#include <stdio.h>
#include <math.h>
#include<stdlib.h>
int main(){
int n = 0, a=1, counter = 0;
double sum = 0, product = 0, result = 0;
printf("Input n:");
scanf("%d", &n);
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
int n = 0, a=1, counter = 0;
double sum = 0;
double product = 1;
printf("Input n:");
scanf("%d", &n);
a *= 3;
sum += (((double)a*log(i+1))/product);
counter += 9;
}
printf("the result is equel to %7f\n", sum);
printf("the number of operations is equel to %d\n", counter);
return 0;
}
Таблиця результатів запуску програм для різних значень n=1,2,3,10,20,30,50,100
n 1 2 3 10 20 30 50 100
Кількість Перший 17 38 64 386 1271 2656 6926 26351
операцій спосіб
Другій 13 25 37 121 241 361 601 1201
спосіб
Назва діаграми
30000
25000
20000
15000
10000
5000
0
1 2 3 10 20 30 50 100 n
Висновок
Метод динамічного програмування значно оптимізує програму через зменшення кількості операцій.