123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- #include <stdio.h>
- #include <locale.h>
- #include <string.h>
- #include <math.h>
- void vvod(int task, float* arguments) {
- if (task == 1) {
- printf_s("Ââåäèòå êîýôôèöèåíòû a, b è c: ");
- while (scanf_s("%f %f %f", &arguments[0], &arguments[1], &arguments[2]) != 3) {
- printf("Îøèáêà ââîäà. Ïîæàëóéñòà, ââåäèòå òðè ÷èñëà: ");
- while (getchar() != '\n');
- }
- }
- else if (task == 2) {
- printf_s("Ââåäèòå êîýôôèöèåíòû ñèñòåìû (a1, b1, c1, a2, b2, c2): ");
- while (scanf_s("%f %f %f %f %f %f", &arguments[0], &arguments[1], &arguments[2],
- &arguments[3], &arguments[4], &arguments[5]) != 6) {
- printf_s("Îøèáêà ââîäà. Ïîæàëóéñòà, ââåäèòå øåñòü ÷èñåë: ");
- while (getchar() != '\n');
- }
- }
- else if (task == 3) {
- printf_s("Ââåäèòå ÷èñëî äëÿ âû÷èñëåíèÿ ôàêòîðèàëà: ");
- while (scanf_s("%f", &arguments[0]) != 1 || arguments[0] < 0 || arguments[0] != (float)arguments[0]) {
- printf_s("Îøèáêà ââîäà. Ïîæàëóéñòà, ââåäèòå íåîòðèöàòåëüíîå öåëîå ÷èñëî: ");
- while (getchar() != '\n');
- }
- }
- }
- void vivod(int task, float* x, int numRoots) {
- if (task == 1) {
- if (numRoots == 1) {
- printf_s("Êîðåíü óðàâíåíèÿ: %.2f\n", x[0]);
- }
- 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) {
- if (numRoots == 0)
- {
- printf_s("Ðåøåíèå ñèñòåìû: x = %.2f, y = %.2f\n", x[0], x[1]);
- }
- else
- {
- printf_s("Ñèñòåìà íå èìååò åäèíñòâåííîãî ðåøåíèÿ.\n");
- }
- }
- else if (task == 3) {
- printf_s("Ôàêòîðèàë ÷èñëà %.2f ðàâåí: %.20f\n", x[0], x[1]);
- }
- }
- int Task1(float* arguments, float* x) {
- float a = arguments[0];
- float b = arguments[1];
- float c = arguments[2];
- float D = b * b - 4 * a * c;
- 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; // Äâà êîðíÿ
- }
- else if (D == 0) {
- x[0] = -b / (2 * a);
- return 1; // Îäèí êîðåíü
- }
- else {
- return 0; // Íåò äåéñòâèòåëüíûõ êîðíåé
- }
- }
- 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];
- float D = a1 * b2 - a2 * b1;
- if (D != 0) {
- // Ðåøåíèå ñèñòåìû
- x[0] = (c1 * b2 - c2 * b1) / D; // x
- x[1] = (a1 * c2 - a2 * c1) / D; // y
- return 0;
- }
- else {
- return 1;
- }
- }
- double Task3(float n) {
- if (n == 0 || n == 1) {
- return 1;
- }
- double result = 1;
- for (int i = 2; i <= n; i++) {
- result *= i;
- }
- return result;
- }
- int main() {
- float arguments[6];
- float roots[2]; // Ìàññèâ äëÿ õðàíåíèÿ êîðíåé
- int task;
- setlocale(LC_ALL, "Russian");
- printf_s("Ââåäèòå íîìåð çàäàíèÿ (1 - êâàäðàòíîå óðàâíåíèå, 2 - ñèñòåìà óðàâíåíèé, 3 - ôàêòîðèàë): ");
- scanf_s("%d", &task);
- vvod(task, arguments);
- if (task == 1) {
- int numRoots = Task1(arguments, roots);
- vivod(task, roots, numRoots);
- }
- else if (task == 2) {
- Task2(arguments, roots);
- int numRoots = Task2(arguments, roots);
- vivod(task, roots, numRoots);
- }
- else if (task == 3) {
- int n = (int)arguments[0];
- roots[0] = n; // Ñîõðàíÿåì ÷èñëî äëÿ âûâîäà
- roots[1] = Task3(n); // Âû÷èñëÿåì ôàêòîðèàë
- vivod(task, roots, 0);
- }
- return 0;
- }
|