#include<stdio.h>
#include<math.h>
int main()
{
float a,b,c,r1,r2,img1,img2,disc;
printf("\nENTER THE Co-officients\n");
scanf("%f%f%f",&a,&b,&c);
if (a==0)
{
if (b==0)
printf("Equation is Degenerate\n");
else
{
printf("Linear equation has single root");
r1=-c/b;
printf("\nRoot=%.2f",r1);
}
}
else
{
disc=(b*b)-(4*a*c);
if(disc>0)
{
printf("Real and disctinct roots\n");
r1=(-b+sqrt(disc))/(2*a);
r2=(-b-sqrt(disc))/(2*a);
img1=img2=0;
}
else
{
if(disc==0)
{
printf("Real and equal roots\n");
r1=r2=(-b)/(2*a);
img1=img2=0;
}
else
{
printf("Imaginary roots\n");
r1=r2=-b/(2*a);
img1=sqrt(-disc)/(2*a);
img2=img1;
}
}
printf("\nFirst root is \n");
printf("\nReal part=%.2f Imaginary part=%.2f\n",r1,img1);
printf("\nSecond root");
printf("\nReal part=%.2f Imaginary part=%.2f\n",r2,img2);
}
return 0;
}
Have a Read!
Hi Everyone.
The idea for this page is to provide new c users simple c tutorials to learn how to develop the logic and more importantly correct way to write syntax.
ENJOY !!!
Thursday, January 27, 2011
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment