Lerka 1 maand geleden
bovenliggende
commit
bf5201ec14
1 gewijzigde bestanden met toevoegingen van 68 en 19 verwijderingen
  1. 68 19
      Project1/Source.c

+ 68 - 19
Project1/Source.c

@@ -1,12 +1,29 @@
-
+#define _CRT_SECURE_NO_WARNINGS
 #include <stdio.h>
 #include <math.h>
 #include <stdlib.h>
 #include <setjmp.h>
 
 
-
-
+int intputChar()
+{
+    float n; 
+    char t;
+    while (1)
+    {
+        if (scanf("%f%c", &n, &t) != 2 || t != "\n")
+        {
+            printf("îøèáêà. ââåäåíî íåêîððåêòíîå çíà÷åíèå\n");
+            printf("Ïîïðîáóéòå ñíîâà: \n");
+          /*  printf("Ïîïðîáóéòå ñíîâà: \n");
+            printf("Ïîïðîáóéòå ñíîâà: \n");
+            printf("Ïîïðîáóéòå ñíîâà: \n");*/
+            while (getchar() != '\n');
+        }
+        else break;
+    }
+    return n;
+}
 
 
 int Input(float* a, float* b, float* c, float* a2, float* b2, float* c2, float choice)
@@ -42,6 +59,7 @@ int Input(float* a, float* b, float* c, float* a2, float* b2, float* c2, float c
    
         printf("Ââåäèòå ÷èñëî, ôàêòîðèàë êîòîðîãî õîòèòå âû÷èñëèòü: \n");
         scanf_s("%f", a);
+
     }
 
     return 0;
@@ -78,24 +96,31 @@ void square(float a, float b, float c, float* res1, float* res2)
     else if (discriminant == 0)
     {
         * res1 = -b / (2 * a);
-        *res2 = 0;
+        *res2 = -9999;
     }
     else
     {
-        //íà ñëó÷àé åñëè ïîëüçîâàòåëü ââåäåò íóëåâîé êîýôôèöèåíò à
+      
         *res1 = -c / b;
-        *res2 = 0;
+        *res2 = -9999;
     }
 }
 
 void Factorial(float a, float* res1)
 {
-    float buf = 1;
-    for (int i = 1; i <= a; i++)
+    if (a == 0)
+    {
+        *res1 = 1;
+    }
+    else
     {
-        buf = buf * i;
+        float buf = 1;
+        for (int i = 1; i <= a; i++)
+        {
+            buf = buf * i;
+        }
+        *res1 = buf;
     }
-    *res1 = buf;
 
     
 }
@@ -105,7 +130,7 @@ int output(float a, float b, float c, float a2, float b2, float c2, float res1,
 {
     if (choice == 1)
     {
-        if (res1 != 0 && res2 != 0) printf("Êîðåíü õ1 ðàâåí  %-6.2f\nÊîðåíü õ2 ðàâåí  %-6.2f\n", res1, res2);
+        if (res1 != 0 && res2 != -9999) printf("Êîðåíü õ1 ðàâåí  %-6.2f\nÊîðåíü õ2 ðàâåí  %-6.2f\n", res1, res2);
         else if(res1!=0)  printf("Êîðåíü õ ðàâåí  %-6.2f\n", res1);
         else printf("Êîðíåé íåò");
        
@@ -116,7 +141,7 @@ int output(float a, float b, float c, float a2, float b2, float c2, float res1,
     }
     else
     {
-        printf("Ôàêòîðèàë ÷èñëà  %-6.2f ðàâåí %-6.2f\n",a,res1);
+        printf("Ôàêòîðèàë ÷èñëà  %-6.0d ðàâåí %-6.0d\n",(int)a,(int)res1);
     }
 
     return 0;
@@ -141,21 +166,45 @@ int main(void)
     case 1:
         printf("êâàäðàòíîå óðàâíåíèå\n");
         Input(&a, &b, &c, &a2, &b2, &c2, choice);
-        square(a,b,c,&res1,&res2);
-        output(a, b, c, a2, b2, c2, res1, res2, choice);
+        if(a==0 && b==0 )
+        {
+            printf("îøèáêà. íå èìååò ðåøåíèé\n");
+            /*Input(&a, &b, &c, &a2, &b2, &c2, choice);*/
+        }
+        else 
+        {
+            square(a, b, c, &res1, &res2);
+            output(a, b, c, a2, b2, c2, res1, res2, choice);
+        }
+        
         break;
     case 2:
         printf("ñèñòåìà äâóõ ëèíåéíûõ óðàâíåíèé\n");
         Input(&a, &b, &c, &a2, &b2, &c2, choice);
-        kramer(a, b, c, a2, b2, c2, &res1, &res2);
-        output(a, b, c, a2, b2, c2, res1, res2, choice);
-        
+        if ((a == 0 && b == 0 )|| (a2 == 0 && b2 == 0))
+        {
+            printf("îøèáêà. Îäíî èëè îáà óðàâíåíèé èç ñèñòåìû íå èìååò ðåøåíèé\n");
+            /*Input(&a, &b, &c, &a2, &b2, &c2, choice);*/
+        }
+        else
+        {
+            kramer(a, b, c, a2, b2, c2, &res1, &res2);
+            output(a, b, c, a2, b2, c2, res1, res2, choice);
+        }
         break;
     case 3:
         printf("ïåðåñòàíîâêè (ôàêòîðèàë)\n");
         Input(&a, &b, &c, &a2, &b2, &c2, choice);
-        Factorial(a,&res1);
-        output(a, b, c, a2, b2, c2, res1, res2, choice);
+        if (a < 0)
+        {
+            printf("äëÿ ïîä÷åòà ôàêòîðèàëà ìîæíî èñïîëüçîâàòü òîëüêî ïîëîæèòåëüíûå ÷èñëà\n");
+        }
+        else 
+        {
+            Factorial(a, &res1);
+            output(a, b, c, a2, b2, c2, res1, res2, choice);
+        }
+        
         break;
     default:
         printf("Òàêîãî çàäàíèÿ íåò\n");