Advertisement
WadeRollins2710

Solve Unknowns and Degree Equation Application

Nov 16th, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.11 KB | None | 0 0
  1. //Equation
  2. #include<stdio.h>
  3. #include<windows.h>
  4. #include<math.h>
  5.  
  6. void SolveEquation2( )
  7. {
  8.     printf("Solve Equation Succeed!\n");
  9. }
  10.  
  11. void SolveEquation1( )
  12. {
  13.     printf("Solve Equation Succeed!\n");
  14. }
  15.  
  16. void InputDataUnk( )
  17. {
  18.     float a1, b1, c1, a2, b2, c2;
  19.     float D, Dx, Dy;
  20.     printf("Input a1, b1, c1: ");
  21.     scanf("%f %f %f", &a1, &b1, &c1);
  22.     printf("Input a2, b2, c2: ");
  23.     scanf("%f %f %f", &a2, &b2, &c2);
  24.     D=a1*b2-a2*b1;
  25.     Dx=c1*b2-c2*b1;
  26.     Dy=a1*c2-a2*c1;
  27.     if (D!=0)
  28.         printf("x=%.2f; y=%.2f", D/Dx, D/Dy);
  29.     else
  30.         {
  31.             if ( (Dx!=0) || (Dy!=0) )
  32.                 printf("No solution!\n");
  33.             if ( (Dx==0) && (Dy==0) )
  34.                 printf("Infinite solution!\n");
  35.         }
  36. }
  37.  
  38. void InputDataDgr( )
  39. {
  40.     int choice;
  41.     float a, b, c;
  42.     float Delta;
  43.     printf("1.Superlative\n2.Quadratic\nInput choice: ");
  44.     scanf("%d", &choice);
  45.     while ( (choice!=1) && (choice!=2) )
  46.     {
  47.         printf("Input again: ");
  48.         scanf("%d", &choice);
  49.     }
  50.     if (choice==1)
  51.     {
  52.         printf("Input a, b: ");
  53.         scanf("%f %f", &a, &b);
  54.         if (a==0)
  55.             if (b==0) printf("Infinite solution!\n");
  56.             else
  57.                 printf("No solution!\n");
  58.         else printf("x=%.2f\n",-b/a);
  59.     }
  60.     if (choice==2)
  61.     {
  62.         printf("Input a, b, c: ");
  63.         scanf("%f %f %f", &a, &b, &c);
  64.         Delta=b*b-4*a*c;
  65.         if (Delta==0) printf("One solution: x=%.2f\n", -b/2*a);
  66.         if (Delta>0) printf("Two different solution: \n x1=%.2f; x2=%.2f\n", (-b - sqrt(Delta))/ 2*a , (-b + sqrt(Delta))/2 );
  67.         if (Delta<0) printf("No solution!\n");
  68.     }
  69. }
  70.  
  71. int main( )
  72. {
  73.     int choice;
  74.     system("cls");
  75.     printf("1.Unknowns\n2.Degree\nInput choice: ");
  76.     scanf("%d", &choice);
  77.     while ( (choice!=1) && (choice!=2) )
  78.     {
  79.         printf("Input again: ");
  80.         scanf("%d", &choice);
  81.     }
  82.     if (choice==1)
  83.     {
  84.         InputDataUnk( );
  85.         SolveEquation1( );
  86.     }
  87.     if (choice==2)
  88.     {
  89.         InputDataDgr( );
  90.         SolveEquation2( );
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement