Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Equation
- #include<stdio.h>
- #include<windows.h>
- #include<math.h>
- void SolveEquation2( )
- {
- printf("Solve Equation Succeed!\n");
- }
- void SolveEquation1( )
- {
- printf("Solve Equation Succeed!\n");
- }
- void InputDataUnk( )
- {
- float a1, b1, c1, a2, b2, c2;
- float D, Dx, Dy;
- printf("Input a1, b1, c1: ");
- scanf("%f %f %f", &a1, &b1, &c1);
- printf("Input a2, b2, c2: ");
- scanf("%f %f %f", &a2, &b2, &c2);
- D=a1*b2-a2*b1;
- Dx=c1*b2-c2*b1;
- Dy=a1*c2-a2*c1;
- if (D!=0)
- printf("x=%.2f; y=%.2f", D/Dx, D/Dy);
- else
- {
- if ( (Dx!=0) || (Dy!=0) )
- printf("No solution!\n");
- if ( (Dx==0) && (Dy==0) )
- printf("Infinite solution!\n");
- }
- }
- void InputDataDgr( )
- {
- int choice;
- float a, b, c;
- float Delta;
- printf("1.Superlative\n2.Quadratic\nInput choice: ");
- scanf("%d", &choice);
- while ( (choice!=1) && (choice!=2) )
- {
- printf("Input again: ");
- scanf("%d", &choice);
- }
- if (choice==1)
- {
- printf("Input a, b: ");
- scanf("%f %f", &a, &b);
- if (a==0)
- if (b==0) printf("Infinite solution!\n");
- else
- printf("No solution!\n");
- else printf("x=%.2f\n",-b/a);
- }
- if (choice==2)
- {
- printf("Input a, b, c: ");
- scanf("%f %f %f", &a, &b, &c);
- Delta=b*b-4*a*c;
- if (Delta==0) printf("One solution: x=%.2f\n", -b/2*a);
- if (Delta>0) printf("Two different solution: \n x1=%.2f; x2=%.2f\n", (-b - sqrt(Delta))/ 2*a , (-b + sqrt(Delta))/2 );
- if (Delta<0) printf("No solution!\n");
- }
- }
- int main( )
- {
- int choice;
- system("cls");
- printf("1.Unknowns\n2.Degree\nInput choice: ");
- scanf("%d", &choice);
- while ( (choice!=1) && (choice!=2) )
- {
- printf("Input again: ");
- scanf("%d", &choice);
- }
- if (choice==1)
- {
- InputDataUnk( );
- SolveEquation1( );
- }
- if (choice==2)
- {
- InputDataDgr( );
- SolveEquation2( );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement