123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include<math.h>
- #include<malloc.h>
- void output(char str[50])
- {
- printf(str);
- }
- double quadratic_equation(int a, int b, int c)
- {
- char result[50];
- double D = pow(b, 2) - 4 * a * c;
- if (a == 0)
- {
- double x1 = -c / b;
- sprintf(result, "%f\n", x1);
- output(result);
- }
- else if(D > 0)
- {
- if (D > 0)
- {
- double x1 = (-b + sqrt(D)) / (2 * a);
- double x2 = (-b - sqrt(D)) / (2 * a);
- sprintf(result, "%f,%f\n", x1, x2);
- output(result);
- }
- else if (D == 0)
- {
- double x1 = (-b) / (2 * a);
- sprintf(result, "%f\n", x1);
- output(result);
- }
- else
- {
- strcpy(result, "Êîðíåé íåò\n");
- output(result);
- }
- }
- else
- {
- strcpy(result, "Ëîæíûå äàííûå\n");
- output(result);
- }
-
- }
- double system_equations(int a1, int b1, int c1, int a2, int b2, int c2)
- {
- char result[50];
- double D = a1 * b2 - a2 * b1;
- if (D == 0)
- {
- strcpy(result, "Ëîæíûå äàííûå\n");
- output(result);
- }
- else
- {
- double x1 = (c1 * b2 - c2 * b1) / D;
- double x2 = (a1 * c2 - a2 * c1) / D;
- printf("%f, %f\n", x1, x2);
- output(result);
- }
-
- }
- double factorial(int a)
- {
- char result[50];
- if (a < 0 || (a*10)%10 != 0)
- {
- strcpy(result, "Ëîæíûå äàííûå\n");
- output(result);
- }
- else if (a == 0)
- {
- int F = 1;
- sprintf(result, "%d\n", F);
- output(result);
- }
- else
- {
- int F = 1;
- for (size_t i = 1; i <= a; i++)
- {
- F = F * i;
- }
- sprintf(result, "%d\n", F);
- output(result);
- }
- }
- void input(int n)
- {
- int result;
- if (n == 1)
- {
- int a, b, c;
- printf("Ââåäèòå a, b, c\n");
- scanf("%d%d%d", &a, &b, &c);
- quadratic_equation(a, b, c);
- }
- if (n == 2)
- {
- int a1, b1, c1, a2, b2, c2;
- printf("Ââåäèòå a1, b1, c1, a2, b2, c2\n");
- scanf("%d%d%d%d%d%d", &a1, &b1, &c1, &a2, &b2, &c2);
- system_equations(a1, b1, c1, a2, b2, c2);
- }
- if (n == 3)
- {
- int a;
- printf("Ââåäèòå a\n");
- scanf("%d", &a);
- factorial(a);
- }
- else
- {
- printf("Òàêîãî çàäàíèÿ íåò/íåâåðíî\n");
- }
- }
- int main()
- {
- system("chcp 1251>nul");
- while (1)
- {
- int n;
- printf("Âûáåðèòå çàäà÷êó äëÿ ðåøåíèÿ:\n1. Êâàäðàòíîå óðàâíåíèå\n2. Ñèñòåìà óðàâíåíèé\n3. Ôàêòîðèàë\n0. Âûõîä\n");
- scanf("%d", &n);
- input(n);
- }
-
- }
|