Advertisement
sedran

Finding Delta and Roots

May 7th, 2011
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4. float delt(float a,float b,float c){
  5.     float sonuc;
  6.     sonuc= b*b-4*a*c;
  7.     return sonuc;
  8. }
  9.  
  10. float solve(float a,float b,float c,float *root1,float *root2){
  11.     float delta,sonuc;
  12.    
  13.     if(a==0){
  14.         return -1;
  15.     }
  16.    
  17.     delta=delt(a,b,c);
  18.    
  19.     if(sonuc==0){
  20.         *root1=(-1*b/2*a);
  21.         return 1;
  22.     }
  23.    
  24.     if(sonuc<0){
  25.         return 0;
  26.     }
  27.    
  28.     *root1=(-1*b+sqrt(delt(a,b,c)))/2*a;
  29.     *root2=(-1*b-sqrt(delt(a,b,c)))/2*a;
  30.     return 2;
  31. }
  32. int main(){
  33.     int solved;
  34.     float a,b,c;
  35.     float r1,r2;
  36.     scanf("%f%f%f",&a,&b,&c);
  37.     solved = solve(a,b,c,&r1,&r2);
  38.     if(solved == -1) {
  39.         printf("not quadratic\n");
  40.     }
  41.     if(solved == 1){
  42.         printf("r1=r2: %f",r1);
  43.     }
  44.     if(solved == 2){
  45.         printf("r1: %f r2: %f",r1,r2);
  46.     }
  47.     system("pause");
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement