Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
сука лаби.docx
Скачиваний:
19
Добавлен:
12.05.2015
Размер:
848 Кб
Скачать
☆

Додаток

Програми виконують завдання:

Від яких елементів одновимірного масиву задана функція отримує найбільше та найменше значення та їх суму.

#include <iostream.h>

#include <math.h>

#include <conio.h>

float f(float z)

{

return 2*z*z*z -4*z*z+7*sin(3*3.1415926*z)/z;

}

void main()

{

float x[7]={0.1,7.1,-3.5,4.5,0.5,-0.7,5.3},s;

int ind1=0,ind2=0,i;

clrscr();

float fmax=f(x[0]),fmin(x[0]),g;

for(i=1;i<7;i++)

{

g=f(x[i]);

if(g>fmax)

{

fmax=g;ind1=i;

}

if(g<fmin)

{

fmin=g;ind2=i;

}

}

s=fmin+fmax;

cout<<"\n s="<<s;

cout<<"\n ind1="<<ind1;

cout<<"\n ind2="<<ind2;

getch();

}

#include <iostream.h>

#include <math.h>

#include <conio.h>

#include "PREPRO.h"

float f(float z)

BEGIN

return 2*CUB(z)-4*SQ(z)+DIV(7*sin(3*PI*z),z);

END

void main()

BEGIN

float x[n]={0.1,7.1,-3.5,4.5,0.5,-0.7,5.3},s;

int ind1=0,ind2=0,i;

clrscr();

float fmax=f(x[0]),fmin(x[0]),g;

for_do(i,1,n)

BEGIN

g=f(x[i]);

if(greater_than(g,fmax))

BEGIN

fmax=g;ind1=i;

END

if(g<fmin)

BEGIN

fmin=g;ind2=i;

END

END

s=SUM(fmin,fmax);

out(s);

out(ind1);

out(ind2);

getch();

END

Файл PREPRO.h

#define n 7

#define PI 3.1415926

#define EQUAL ==

#define BEGIN {

#define END }

#define for_do(x,l,n) for((x)=(l);(x)<(n);(x)++)

#define greater_than(a,b) ((a)>(b))? 1:0

#define out(a) cout<<"\n "#a"="<<(a)

#define MAX(x,y) ((x)<(y))? (y):(x)

#define SUM(x,y) ((x)+(y))

#define DIV(x,y) ((x)/(y))

#define CUB(x) ((x)*(x)*(x))

#define SQ(x) ((x)*(x))

Обидві програми видають такий результат:

s=3890.634338

ind1=1

ind2=2

Для другої програми треба створити проект із двох файлів, інакше команди препроцесора треба включити у програму

#include <iostream.h>

#include <math.h>

#include <conio.h>

#define n 7

#define PI 3.1415926

#define EQUAL ==

#define BEGIN {

#define END }

#define for_do(x,l,n) for((x)=(l);(x)<=(n);(x)++)

#define greater_than(a,b) ((a)>(b))? 1:0

#define out(a) cout<<"\n"#a"="<<(a)

#define MAX(x,y) ((x)<(y))? (y):(x)

#define SUM(x,y) ((x)+(y))

#define DIV(x,y) ((x)/(y))

#define CUB(x) ((x)*(x)*(x))

#define SQ(x) ((x)*(x))

float f(float z)

BEGIN

return 2*CUB(z)-4*SQ(z)+DIV(7*sin(3*PI*z),z);

END

void main()

BEGIN

float x[n]={0.1,7.1,-3.5,4.5,0.5,-0.7,5.3},s;

int ind1=0,ind2=0,i;

clrscr();

float fmax=f(x[0]),fmin(x[0]),g;

for_do(i,1,n)

BEGIN

g=f(x[i]);

if(greater_than(g,fmax))

BEGIN

fmax=g;ind1=i;

END

if(g<fmin)

BEGIN

fmin=g;ind2=i;

END

END

s=SUM(fmin,fmax);

out(s);

out(ind1);

out(ind2);

getch();

END

Лабораторна робота №13

РОБОТА ІЗ КОМПЛЕКСНИМИ ЧИСЛАМИ

Мета роботи :ознайомлення із способами встановлення комплексного типу даних , вивчення виконання обчислень виразів та функцій із комплексними числами і створення відповідних комп’ютерних програм.