WELCOME

Welcome to KoDes4U

Pages

Thursday, March 3, 2011

Quadratic Equation Code(C program)

/*Write a program to find a quadratic equation ax2+bx+c=0.

Coded for KoDes4U.blogspot.com*/

#include

#include

#include

void main()

{

int a,b,c,disc;

float alpha,beta;

clrscr();

printf("\nEnter the value of a,b and c:");

scanf("%d%d%d",&a,&b,&c);

disc=(b*b)-(4*a*c);

if(disc<0)

printf("\nRoots are imaginary.");

else

{

alpha=(-b+sqrt(disc))/(2*a);

beta=(-b-sqrt(disc))/(2*a);

printf("\n1st Root=%f\t2nd Root=%f",alpha,beta);

}

getch();

}

No comments:

Post a Comment