Beyond Verses

My blog that specialize in Space Science and Latest news from NASA

Wednesday, November 19, 2008

Quadratic equation in C

// Q equ //
#include <stdio.h>
#include <math.h>
void main()
{
double a,b,c ; // i use this for 0.000 real
double m,n,r ;
double real,imgn ;
printf ("enter var A ") ;
scanf ("%f", &a) ;
printf ("enter var B ") ;
scanf ("%f", &b) ;
printf ("enter var C ") ;
scanf ("%f", &c) ;
r = ( (b*b)-(4*a*c) ) ; /* for specific = 0 , >0 , <0
two sismilar solution , tow difrent solution , comlix root & number */

if (r>=0)
{
m= ( (-b) + sqrt(pow(b,2) - (4*a*c)) ) / (2*a) ;
n = ( (-b) - sqrt(pow(b,2) - (4*a*c)) ) / (2*a) ;


printf ("X1 = %7.3f \n",m ) ;
printf ("X2 = %7.3f \n",n ) ;

}
else
{
printf ("complex root \n") ;


real = (-b)/(2*a) ;
imgn = sqrt(-r) /(2*a) ;
// 7.3 refer to 000.000

printf ("X1 = %7.3f + %7.3f i \n",real,imgn) ;
printf ("X2 = %7.3f - %7.3f i \n",real,imgn) ;
}
}

No comments: