This program is for find roots of polynomial in which X has maximum power is 2 and coefficient of X^2 is not equal to zero.
#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,d,e,f;
printf("enter the coefficient of X^2:");
scanf("%f",&a);
printf("enter the coefficient of X:");
scanf("%f",&b);
printf("enter the value of constant:");
scanf("%f",&c);
d=(b*b)-(4*a*c);
if(d>=0&&a!=0)
{
e=(-b+sqrt(d))/(2*a);
f=(-b-sqrt(d))/(2*a);
printf ("Root 1 =%f",e);
printf ("Root 2 =%f",f);
}
if(d<0&&a!=0)
{
e=-b/(2*a);
f=sqrt(-d)/(2*a);
printf ("Root 1=%f+%fi",e,f);
printf ("Root 1=%f-%fi",e,f);
}
}
For your choice program please tell me in comment box.
#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,d,e,f;
printf("enter the coefficient of X^2:");
scanf("%f",&a);
printf("enter the coefficient of X:");
scanf("%f",&b);
printf("enter the value of constant:");
scanf("%f",&c);
d=(b*b)-(4*a*c);
if(d>=0&&a!=0)
{
e=(-b+sqrt(d))/(2*a);
f=(-b-sqrt(d))/(2*a);
printf ("Root 1 =%f",e);
printf ("Root 2 =%f",f);
}
if(d<0&&a!=0)
{
e=-b/(2*a);
f=sqrt(-d)/(2*a);
printf ("Root 1=%f+%fi",e,f);
printf ("Root 1=%f-%fi",e,f);
}
}
For your choice program please tell me in comment box.