Find roots of quadratic equation (ax^2+bx+c=0)

Program:

#include<stdio.h>
#include<math.h>
int main()
{
float a,b,c,alpha,beta,delta,realpart,imaginarypart;
printf("Enter a,b and c: \n");
scanf("%f %f %f",&a,&b,&c);
delta=(b*b)-(4*a*c);
if(delta==0)
{
  printf("alpha=beta=%f",-b/(2*a));
}
else if(delta<0)
{
realpart=-b/(2*a);
imaginarypart=(sqrt(-delta))/(2*a);
printf("alpha=%f+%fi \n beta=%f-%fi\n",realpart,imaginarypart,realpart,imaginarypart);
}
else
{
alpha=(-b+sqrt(delta))/(2*a);
beta=(-b-sqrt(delta))/(2*a);
printf("alpha=%f \n beta=%f\n",alpha,beta);
}
return 0;

}

Output:





No comments:

Post a Comment

x^y using recursion

Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...