Calculate the real roots of a quadratic equation

  • Thread starter beanryu
  • Start date
  • #1
beanryu
92
0
Please Help!

I designed this "PROGRAM"! TO calculate the real roots of a quadratic equation...

but the compiler miracle C kept saying there's something wrong around the "if" word... saying "unrecognised types in comparison"
it seem SO FINE to me... what is wrong?!:eek:

#include <stdio.h>
#include <math.h>

int main(void)
{
/* Declare variables. */
double a,b,c,d,e,f;

printf("This program computes the real roots of a quadratic equations.\n");
printf("(recall that the general form of quadratic equation is ax^2+bx+c where a, b and c are canstants)\n");

printf("please enter the first coefficient.\n");
scanf("%f", &a);
printf("%f\n",a);

printf("please enter the second coefficient.\n");
scanf("%f", &b);
printf("%f\n",b);

printf("please enter the third coefficient.\n");
scanf("%f", &c);
printf("%f\n",c);

f=(b*b-4*a*c);

if(f<0)
printf("roots are not real.\n");

else
d=((-1)*b+sqrt(f))/(2*a);
e=((-1)*b-sqrt(f))/(2*a);
printf("%f, %f",d,e);

/* Exit program. */
return 0;
}
/*--------------------------------------------------*/
 
Last edited:

Answers and Replies

  • #2
doodle
161
0
1. To read doubles, use %lf in scanf().
2. You will need braces around the else body.
 

Suggested for: Calculate the real roots of a quadratic equation

Replies
5
Views
1K
  • Last Post
Replies
2
Views
91
Replies
19
Views
1K
Replies
102
Views
2K
  • Last Post
Replies
3
Views
409
Replies
10
Views
982
Replies
35
Views
2K
  • Last Post
Replies
8
Views
511
Replies
8
Views
305
Replies
24
Views
655
Top