Fix Lesson 1

This commit is contained in:
Stanislav Mykhailenko 2024-06-11 10:48:26 +03:00
parent c1ab9980d4
commit 0ae4eb5552
GPG key ID: 1E95E66A9C9D6A36
7 changed files with 65 additions and 52 deletions

View file

@ -1,7 +1,10 @@
#include <iostream> #include <iostream>
using namespace std;
int main() int main()
{ {
std::cout << "Stanislav" << std::endl << "Mykhailenko" << std::endl; cout << "Stanislav" << endl;
cout << "Mykhailenko" << endl;
return 0; return 0;
} }

View file

@ -1,17 +1,19 @@
#include <iostream> #include <iostream>
using namespace std;
int main() int main()
{ {
float firstNumber = 0; float firstNumber = 0;
float secondNumber = 0; float secondNumber = 0;
std::cout << "Enter the first number: "; cout << "Enter the first number: ";
std::cin >> firstNumber; cin >> firstNumber;
std::cout << "Enter the second number: "; cout << "Enter the second number: ";
std::cin >> secondNumber; cin >> secondNumber;
std::cout << firstNumber + secondNumber << std::endl; cout << firstNumber + secondNumber << endl;
return 0; return 0;
} }

View file

@ -1,21 +1,23 @@
#include <iostream> #include <iostream>
using namespace std;
int main() int main()
{ {
int money = 0; int money = 0;
std::cout << "How much money do you earn? "; cout << "How much money do you earn? ";
std::cin >> money; cin >> money;
if (money < 1000) if (money < 1000)
std::cout << "Work more. "; cout << "Work more. ";
if (money > 1000) { if (money > 1000) {
if (money > 1000000) if (money > 1000000)
std::cout << "You are a millionaire. "; cout << "You are a millionaire. ";
if (money < 1000000) if (money < 1000000)
std::cout << "You work great. "; cout << "You work great. ";
} }
std::cout << "You are doing great!" << std::endl; cout << "You are doing great!" << endl;
return 0; return 0;
} }

View file

@ -1,20 +1,22 @@
#include <iostream> #include <iostream>
using namespace std;
int main() int main()
{ {
float firstNumber = 0; float firstNumber = 0;
float secondNumber = 0; float secondNumber = 0;
float result = 0; float result = 0;
char operation; char operation = 0;
std::cout << "Enter the first number: "; cout << "Enter the first number: ";
std::cin >> firstNumber; cin >> firstNumber;
std::cout << "Enter the second number: "; cout << "Enter the second number: ";
std::cin >> secondNumber; cin >> secondNumber;
std::cout << "Enter operation: "; cout << "Enter operation: ";
std::cin >> operation; cin >> operation;
switch (operation) { switch (operation) {
case '+': case '+':
@ -28,18 +30,18 @@ int main()
break; break;
case '/': case '/':
if (secondNumber == 0) { if (secondNumber == 0) {
std::cout << "Division by zero" << std::endl; cout << "Division by zero" << endl;
return 1; return 1;
} }
result = firstNumber / secondNumber; result = firstNumber / secondNumber;
break; break;
default: default:
std::cout << "Unknown operation." << std::endl; cout << "Unknown operation." << endl;
return 2; return 2;
break; break;
} }
std::cout << result << std::endl; cout << result << endl;
return 0; return 0;
} }

View file

@ -2,6 +2,8 @@
#include <complex> #include <complex>
#include <iostream> #include <iostream>
using namespace std;
int main() int main()
{ {
float a = 0; float a = 0;
@ -9,24 +11,24 @@ int main()
float c = 0; float c = 0;
float D = 0; float D = 0;
std::cout << "Enter a: "; cout << "Enter a: ";
std::cin >> a; cin >> a;
std::cout << "Enter b: "; cout << "Enter b: ";
std::cin >> b; cin >> b;
std::cout << "Enter c: "; cout << "Enter c: ";
std::cin >> c; cin >> c;
D = pow(b, 2) - 4 * a * c; D = pow(b, 2) - 4 * a * c;
std::complex<float> root = std::sqrt(std::complex<float>(D)); complex<float> root = sqrt(complex<float>(D));
std::complex<float> x1 = (-b + root) / (2 * a); complex<float> x1 = (-b + root) / (2 * a);
std::complex<float> x2 = (-b - root) / (2 * a); complex<float> x2 = (-b - root) / (2 * a);
std::cout << "x1 = " << x1 << std::endl; cout << "x1 = " << x1 << endl;
std::cout << "x2 = " << x2 << std::endl; cout << "x2 = " << x2 << endl;
return 0; return 0;
} }

View file

@ -1,25 +1,27 @@
#include <iostream> #include <iostream>
using namespace std;
int main() int main()
{ {
int size = 0; int size = 0;
std::cout << "Enter size: "; cout << "Enter size: ";
std::cin >> size; cin >> size;
for (int iteration = 0; iteration < size; ++iteration) { for (int iteration = 0; iteration < size; ++iteration) {
int spaces = size - iteration - 1; int spaces = size - iteration - 1;
int asterisks = 1 + iteration * 2; int asterisks = 1 + iteration * 2;
for (int space = 0; space < spaces; ++space) for (int space = 0; space < spaces; ++space)
std::cout << " "; cout << " ";
for (int asterisk = 0; asterisk < asterisks; ++asterisk) for (int asterisk = 0; asterisk < asterisks; ++asterisk)
std::cout << "*"; cout << "*";
std::cout << std::endl; cout << endl;
} }
for (int space = 0; space < size - 1; ++space) for (int space = 0; space < size - 1; ++space)
std::cout << " "; cout << " ";
std::cout << "*" << std::endl; cout << "*" << endl;
return 0; return 0;
} }

View file

@ -1,6 +1,8 @@
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
using namespace std;
int main() int main()
{ {
float x = 0; float x = 0;
@ -8,23 +10,21 @@ int main()
float N = 0; float N = 0;
float distance = 0; float distance = 0;
std::cout << "x = "; cout << "Enter your x: ";
std::cin >> x; cin >> x;
std::cout << "y = "; cout << "Enter your y: ";
std::cin >> y; cin >> y;
std::cout << "N = "; cout << "Enter radius N: ";
std::cin >> N; cin >> N;
if (x > N || y > N) {
std::cout << "Beyond radius." << std::endl;
return 1;
}
distance = sqrt(pow(x, 2) + pow(y, 2)); distance = sqrt(pow(x, 2) + pow(y, 2));
std::cout << distance << std::endl; cout << distance << " from the center";
if (distance > N)
cout << " (beyond radius)";
cout << endl;
return 0; return 0;
} }