|
@@ -3,6 +3,8 @@
|
|
|
#include <string.h>
|
|
|
#include <math.h>
|
|
|
|
|
|
+
|
|
|
+
|
|
|
void vvod(int task, float* arguments) {
|
|
|
if (task == 1) {
|
|
|
printf_s("Ââåäèòå êîýôôèöèåíòû a, b è c: ");
|
|
@@ -21,7 +23,7 @@ void vvod(int task, float* arguments) {
|
|
|
}
|
|
|
else if (task == 3) {
|
|
|
printf_s("Ââåäèòå ÷èñëî äëÿ âû÷èñëåíèÿ ôàêòîðèàëà: ");
|
|
|
- while (scanf_s("%f", &arguments[0]) != 1 || arguments[0] < 0 || arguments[0] != (int)arguments[0]) {
|
|
|
+ while (scanf_s("%f", &arguments[0]) != 1 || arguments[0] < 0 || arguments[0] != (float)arguments[0]) {
|
|
|
printf_s("Îøèáêà ââîäà. Ïîæàëóéñòà, ââåäèòå íåîòðèöàòåëüíîå öåëîå ÷èñëî: ");
|
|
|
while (getchar() != '\n');
|
|
|
}
|
|
@@ -36,15 +38,26 @@ void vivod(int task, float* x, int numRoots) {
|
|
|
else if (numRoots == 2) {
|
|
|
printf_s("Êîðíè óðàâíåíèÿ: %.2f\n%.2f\n", x[0], x[1]);
|
|
|
}
|
|
|
+ else if (numRoots == 3)
|
|
|
+ {
|
|
|
+ printf_s("Àðãóìåíòû íå ìîãóò áûòü îòðèöàòåëüíûìè.\n");
|
|
|
+ }
|
|
|
else {
|
|
|
printf_s("Íåò äåéñòâèòåëüíûõ êîðíåé.\n");
|
|
|
}
|
|
|
}
|
|
|
else if (task == 2) {
|
|
|
- printf_s("Ðåøåíèå ñèñòåìû: x = %.2f, y = %.2f\n", x[0], x[1]);
|
|
|
+ if (numRoots == 0)
|
|
|
+ {
|
|
|
+ printf_s("Ðåøåíèå ñèñòåìû: x = %.2f, y = %.2f\n", x[0], x[1]);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ printf_s("Ñèñòåìà íå èìååò åäèíñòâåííîãî ðåøåíèÿ.\n");
|
|
|
+ }
|
|
|
}
|
|
|
else if (task == 3) {
|
|
|
- printf_s("Ôàêòîðèàë ÷èñëà %.0f ðàâåí: %.0f\n", x[0], x[1]);
|
|
|
+ printf_s("Ôàêòîðèàë ÷èñëà %.2f ðàâåí: %.20f\n", x[0], x[1]);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -54,7 +67,12 @@ int Task1(float* arguments, float* x) {
|
|
|
float c = arguments[2];
|
|
|
float D = b * b - 4 * a * c;
|
|
|
|
|
|
- if (D > 0) {
|
|
|
+ if (a == 0 || b == 0 || c == 0)
|
|
|
+ {
|
|
|
+ return 3;
|
|
|
+ }
|
|
|
+
|
|
|
+ else if (D > 0) {
|
|
|
x[0] = (-b + sqrt(D)) / (2 * a);
|
|
|
x[1] = (-b - sqrt(D)) / (2 * a);
|
|
|
return 2; // Äâà êîðíÿ
|
|
@@ -68,7 +86,7 @@ int Task1(float* arguments, float* x) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void Task2(float* arguments, float* x) {
|
|
|
+int Task2(float* arguments, float* x) {
|
|
|
float a1 = arguments[0], b1 = arguments[1], c1 = arguments[2];
|
|
|
float a2 = arguments[3], b2 = arguments[4], c2 = arguments[5];
|
|
|
|
|
@@ -78,17 +96,18 @@ void Task2(float* arguments, float* x) {
|
|
|
// Ðåøåíèå ñèñòåìû
|
|
|
x[0] = (c1 * b2 - c2 * b1) / D; // x
|
|
|
x[1] = (a1 * c2 - a2 * c1) / D; // y
|
|
|
+ return 0;
|
|
|
}
|
|
|
- else {
|
|
|
- printf_s("Ñèñòåìà íå èìååò åäèíñòâåííîãî ðåøåíèÿ.\n");
|
|
|
+ else {
|
|
|
+ return 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-float Task3(int n) {
|
|
|
+double Task3(float n) {
|
|
|
if (n == 0 || n == 1) {
|
|
|
return 1;
|
|
|
}
|
|
|
- float result = 1;
|
|
|
+ double result = 1;
|
|
|
for (int i = 2; i <= n; i++) {
|
|
|
result *= i;
|
|
|
}
|
|
@@ -112,7 +131,8 @@ int main() {
|
|
|
}
|
|
|
else if (task == 2) {
|
|
|
Task2(arguments, roots);
|
|
|
- vivod(task, roots, 0);
|
|
|
+ int numRoots = Task2(arguments, roots);
|
|
|
+ vivod(task, roots, numRoots);
|
|
|
}
|
|
|
else if (task == 3) {
|
|
|
int n = (int)arguments[0];
|