-
Notifications
You must be signed in to change notification settings - Fork 2
GnedykVolodimirn request HomeWork1 #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #include <cmath> | ||
| #include <cstdio> | ||
| #include <iostream> | ||
| int main(int argc, char const *argv[]) { | ||
| std::cout << "Вас приветствует програма Quadratic_equation." << std::endl; | ||
| std::cout | ||
| << "Данная програма предназначена для опредиления решений квадратного " | ||
| "уравнения типа А*х^2+B*х+С=0 над полем действительных чисел." | ||
| << std::endl; | ||
| const short kShortMin = std::numeric_limits<short>::min(); | ||
| const short kShortMax = std::numeric_limits<short>::max(); | ||
| short A; | ||
| std::cout << "Введите значение параметра А в виде целого ненулевого числа в " | ||
| "диапазоне от " | ||
| << kShortMin << " до " << kShortMax << std::endl; | ||
| std::cin >> A; | ||
| // Если А=0, то у нас нет квадратного уравнения | ||
| while ((A < kShortMin) && (A > kShortMax) && (A == 0)) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. у вас эта проверка никогда не выполниться, т.к. тип переменной |
||
| std::cout << "Параметр А задан не верно\n"; | ||
| return 1; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ну тут немного не верно, если вы делаете |
||
| } | ||
| short B; | ||
| std::cout | ||
| << "Введите значение параметра B в виде целого числа в диапазоне от " | ||
| << kShortMin << " до " << kShortMax << std::endl; | ||
| std::cin >> B; | ||
| while ((B < kShortMin) && (B > kShortMax)) { | ||
| std::cout << "Параметр B задан не верно\n"; | ||
| return 1; | ||
| } | ||
| short C; | ||
| std::cout | ||
| << "Введите значение параметра B в виде целого числа в диапазоне от " | ||
| << kShortMin << " до " << kShortMax << std::endl; | ||
| std::cin >> C; | ||
| while ((C < kShortMin) && (C > kShortMax)) { | ||
| std::cout << "Параметр С задан не верно\n"; | ||
| return 1; | ||
| } | ||
| auto D = B ^ 2 - 4 * A * C; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. оператор |
||
| if (D < 0) { | ||
| std::cout | ||
| << "Заданое квадратное уравнение не имеет действительных решеий\n"; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. и что дальше пошли выполнять код? в этом случае вы получили решение и должны сделать |
||
| } | ||
| auto X1 = (-B + std::sqrt(D)) / (2 * A); | ||
| auto X2 = (-B - std::sqrt(D)) / (2 * A); | ||
| std::cout << "Заданое квадратное уравнение имеет 2 действительных решеий\n"; | ||
| std::cout << "Первое решение Х1=" << X1 << std::endl; | ||
| std::cout << "Второе решение Х2=" << X2 << std::endl; | ||
|
|
||
| return 0; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я не очень сильно рекомендую использовать руский текст в консольных приложениях. Ну это на ваше усмотрение)