0

this program is supposed to evaluate an equation of the form f(x)=ax2+bx2+c
using the standard quadratic formula to find x

This is what I've done so far

check=b*b-4*a*c;

	//Validate incoming data
	if (check>0)
	{
		x=-b+sqrt(b*b-4*a*c)/2*a;

		printf("The square root is %.2f",x);
	}
	else

My question is how do I properly represent the quadratic formula using the order of precedence rules?

2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by boujibabe
0

Various conditions can exist depending on the value of check, you havent checked them all. For theory of quadratic equations check here: http://mathworld.wolfram.com/QuadraticEquation.html http://en.wikipedia.org/wiki/Quadratic_equation Also if you taking about the precedence when writing down complex and long statements as in case of quadratic eq. solution, use parantheses instead on relying on your knowledge of precedence, that way you would be safe. If this is not the sol. then again repost with a better explanaiton of what you exactly need giving expamples, and also post your entire code.

0

Sorry I need know if my way of representing the quadratic formula to find x is corect. the check verifies that b squared -4ab is more than zero

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

int main()
{
	double a;
	double b;
	double c;
	double x;
	double check;

	//Get user input
	printf("Please enter  coefficient a");
	scanf_s("%d",&a);
	printf("Please enter coefficient b");
	scanf_s("%d",&b);
	printf("Please enter coefficient c");
	scanf_s("%d",&c);
    
	check=b*b-4*a*c;

	//Validate incoming data
	if (check>0)
	{
		x=-b+sqrt(b*b-4*a*c)/2*a;

		printf("The square root is %.2f",x);
	}
	else
	{
		printf ("Error you coeffecients are less that zero\n");
        printf("Please enter  coefficient a");
	    scanf_s("%d",&a);
	    printf("Please enter coefficient b");
	    scanf_s("%d",&b);
	    printf("Please enter coefficient c");
	    scanf_s("%d",&c);
	}
	
	return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.