Professional Documents
Culture Documents
Лабораторна робота № 3 операторы сравнения, логические операторы
Лабораторна робота № 3 операторы сравнения, логические операторы
Лабораторна робота № 3
“ Створення найпростішої програми з використання логічних операторів та
операторів порівняння, а також конструкцій вибору if else
з дисципліни: «Програмування»
2022 р
if (num1 == num2)
{
cout << "win" << endl;
}
else
{
cout << "lose";
}
return 0;
}
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
srand(time(NULL));
int num1,num2, color;
cout << "entr color (1-red 0-black) - ";
cin >> num1;
cout << "ur num - " << num1 << endl;
color = rand() % 37;
num2 = color % 2;
cout << "color - " << num2 << endl;
if (num1 == color)
{
cout << "win" << endl;
}
else
{
cout << "lose";
}
return 0;
}
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
srand(time(NULL));
int n, q;
cout << "lepestkov - ";
cin >> n;
if ( n % 2 == 1)
{
cout << "love";
}
else
{
cout << "no love";
}
return 0;
}
4. Складіть програму, що грає зі своїм автором в "Орел або решку ".
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
srand(time(NULL));
int num1, coin;
cout << "entr the side (1-orel 0-reshka) - ";
cin >> num1;
cout << "ur side - " << num1 << endl;
coin = rand()%2;
if (num1 == coin)
{
cout << "win" << endl;
}
else
{
cout << "lose";
}
return 0;
}
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
float a,b,c,d,x,z,f,g,h;
z = b - a;
f = z * c;
g = d * x;
h = f + g;
cout << "спожита електроенергія: " << z << " кВт год" << endl;
cout << "вартість електроенергії без піні: " << f << " грн" << endl;
cout<< "сартість піні за прострочення: " << g << " грн" << endl;
cout << "загальна вартість з урахуванням піні: " << h << " грн" << endl;
return 0;
(складно)
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
double beztechii, techiaspeed,vremya,total;
std::cout << "пройдено човном за течією: " << total << "км";
return 0;
}
9. Якщо введений символ є буквою від «А» до «П», то вивести букву,
попередню за алфавітом, якщо від «Р» до «Я», то вивести букву, наступну за
алфавітом.
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
char x,p,n;
if ((x >= 'А' && x <= 'П') || (x >= 'а' && x <= 'п')) {
p = x - 1;
cout << "попередняя буква за алфавітом: " << p << endl;
}
else if ((x >= 'Р' && x <= 'Я') || (x >= 'р' && x <= 'я')) {
n = x + 1;
cout << "наступна буква за алфавітом: " << n << endl;
}
else {
cout << "введений символ не входить в діапазон від 'А' до 'П' або від 'Р' до 'Я'." << endl;
}
return 0;
}
10. Якщо введений символ є цифрою від «1» до «5», то вивести слово
«менше», якщо цифрою від «6» до «9», то вивести «більше».
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
char x;
std::cout << "символ від 1 до 9: ";
std::cin >> x;
return 0;
}
11. Дано 3 числа. Скласти тільки негативні числа з них (знайти суму).
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int a,s,d,f;
f = 0;
if (a < 0) {
f += a;
}
if (s < 0) {
f += s;
}
if (d < 0) {
f += d;
}
return 0;
}