Solving the ax^2+bx+c=0 equation with C language

Source: Internet
Author: User

The solution of ax^2+bx+c=0 equation is obtained by C language.
#include <stdio.h>
#include <math.h>
#define M 0.000001
int main ()
{
float a,b,c,x,x2,n,q,p;
scanf ("%f%f%f", &a,&b,&c);
N=b*b-4*a*c;
if ((a<m) && (a>-m))
{
x= (-c)/b;
printf ("%f", X);
}
else if ((n<m) && (n>-m))
{
x= (-B)/(2*A);
printf ("%f", X);
}
else if (n>0)
{
X= ((-B) +sqrt (n))/(2*A);
X2= ((-B)-sqrt (n))/(2*A);
printf ("%f\n%f", x,x2);
}
Else
{
q= (-B)/(2*A);
P=sqrt (-N)/(2*a);
printf ("%f+%fi\n", q,p);
printf ("%f-%fi\n", q,p);
}
}

Solving the ax^2+bx+c=0 equation with C language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.