Advertisement
Aminpro

October 2011 (b)

Sep 26th, 2012
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. //https://www.facebook.com/AminproPastebin
  2.  
  3. // October 2011
  4. // Question 1 (b)
  5.  
  6. #include <stdio.h>
  7. #include <math.h>
  8.  
  9. int main(){
  10.    
  11.     int a, b, c;
  12.     float x1, x2;
  13.    
  14.    
  15.    
  16.     printf("<--------- Program Starts ---------->\n\n");
  17.     printf("Enter coefficients a, b and c of quadratic equation: ");
  18.     scanf("%d%d%d", &a, &b, &c);
  19.    
  20.     if( (((b)^2)-(4*a*c)) > 0 ){
  21.     if(a != 0){
  22.     x1 = ((-b)-(sqrt((b^2)-(4*a*c))))/(2*a);
  23.     x2 = ((-b)+(sqrt((b^2)-(4*a*c))))/(2*a);
  24.    
  25.     printf("The solutions are %.2f, %.2f\n\n", x2, x1 );
  26. }
  27. else
  28.     printf("Error a ==0\n\n");
  29. }
  30. else printf("The eqn has no real solution : b^2 - 4ac < 0\n\n");
  31.    
  32.     printf("<--- Program Ends and Terminates --->\n");
  33.     getchar();
  34.     getchar();
  35.     return 0;
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement