Professional Documents
Culture Documents
Лабораторна робота №3
Лабораторна робота №3
ЗВІТ
Про виконання лабораторної роботи № 3
“Алгоритмічна конструкція розгалуження”
з дисципліни “АЛГОРИТМІЗАЦІЯ І ПРОГРАМУВАННЯ”
Варіант №16
2020
Лабораторна робота №3
Тема: Алгоритмічна конструкція розгалуження
Мета: Реалізація алгоритмів з розгалуженнями мовою C.
Завдання: Здобути навички створення, відлагодження та реалізації програм з
різними видами алгоритмічних розгалужень мовою C.
GitHub: https://github.com/Aves2001/GitHub_Lab_3_Lebid_Eduard
{
a 2−4 c
, a=2
b= 4 ac
виразу – повідомити користувача про це.
√ ac−2 a , a=4
2
c −4 a , a=6
A)
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <windows.h>
int a = 0;
float b = 0;
float c = 0;
// UTF-8
SetConsoleCP(65001);
SetConsoleOutputCP(65001);
//
printf("a = ");
scanf ("%d",&a);
printf("c = ");
scanf ("%f",&c);
if (a == 2) b = (a*a-4*c) / (4*a*c);
if (a == 4) b = sqrt(a*c-2*a);
if (a == 6) b = c*c-4*a;
// Вертаєм chcp
SetConsoleCP(chcp);
SetConsoleOutputCP(chcpOut);
//
getch();
return 0;
}
B)
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <windows.h>
int a = 0;
float b = 0;
float c = 0;
// UTF-8
SetConsoleCP(65001);
SetConsoleOutputCP(65001);
//
printf("a = ");
scanf ("%d",&a);
printf("c = ");
scanf ("%f",&c);
if (a == 2) b = (a*a-4*c) / (4*a*c);
else if (a == 4) b = sqrt(a*c-2*a);
else if (a == 6) b = c*c-4*a;
// Вертаєм chcp
SetConsoleCP(chcp);
SetConsoleOutputCP(chcpOut);
//
getch();
return 0;
}
Завдання 2. Створити програму згідно свого варіанта:
Частина 1: використати if … else або за необхідності вкладення if…else if
#include <stdio.h>
#include <conio.h>
#include <windows.h>
float x = 0;
float y = 0;
// UTF-8
SetConsoleCP(65001);
SetConsoleOutputCP(65001);
//
// Вертаєм chcp
SetConsoleCP(chcp);
SetConsoleOutputCP(chcpOut);
//
getch();
return 0;
}
Частина 2: використати конструкцію switch…case (1 бал)
16. Задано ціле число n, 1 ≤n ≤ 12, яке вказує порядковий номер місяця в році.
За введеним значенням n надрукувати назву відповідного місяця
#include <stdio.h>
#include <conio.h>
#include <windows.h>
char n = 0;
// UTF-8
SetConsoleCP(65001);
SetConsoleOutputCP(65001);
//
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <windows.h>
double x = 0;
double y = 0;
double f = 0;
// UTF-8
SetConsoleCP(65001);
SetConsoleOutputCP(65001);
//
double a1 = x+y;
double a2 = pow(x,2);
double a3 = x*y;
double a4 = pow(y,2);
double a5 = a4;
double a6 = a2;
double b1 = a2+a3-a4; //n1
double b2 = 1-a5; //n2
double b3 = 1+a6; //n3
double c1 = a1; //v1
double c2 = x; //v2
double c3 = y; //v3
double f1 = (c1/b1);
double f2 = (c2/b2);
double f3 = (c3/b3);
double f = f1 + f2 + f3;
if (b1 == 0 || b2 == 0 || b3 == 0)
{
printf("\r\nДля заданих значень X та Y у обчислюваному виразі
виконується ділення на 0\r\n");
} else printf ("\r\nf = %.2f\r\n", f);
// Вертаєм chcp
SetConsoleCP(chcp);
SetConsoleOutputCP(chcpOut);
getch();
return 0;
}
GitHub: https://github.com/Aves2001/GitHub_Lab_3_Lebid_Eduard