• Uncategorized

Solution of Quadratic Equations Using C

This problem makes you clear about writing Math functions in C. Here I use sqrt() funcitons to calculate the square root. This is the simple program and calculates only real roots. The complete source code and output is given below:
1: #include<stdio.h>
  2: #include<math.h> //must be included
  3: 
  4: int main(){
  5:     float a,b,c,dscr,root1,root2;
  6:     printf("Enter the value of a, b and c: ");
  7:     scanf("%f%f%f",&a,&b,&c);
  8:     dscr = pow(b,2) - 4*a*c;
  9:     if(dscr < 0){
 10:         printf("\nRoots are imaginary\n");
 11:     }else{
 12:         root1 = (-b + sqrt(dscr))/(2.0*a);
 13:         root2 = (-b - sqrt(dscr))/(2.0*a);
 14:         printf("\nRoot1 = %f\nRoot2 = %f",root1,root2);
 15:     }
 16: 
 17:     return 0;
 18: }
 19:

output

 

sqrt

SHARE Solution of Quadratic Equations Using C

You may also like...


Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 9

Warning: Attempt to read property "cat_name" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 9

Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 14

Warning: Attempt to read property "category_parent" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/functions.php on line 37

Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 15

Warning: Attempt to read property "category_parent" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 15
Share