۱۳۸۹ آبان ۲۲, شنبه

حل معادله ی درجه دوم

حل معادله ی درجه دوم
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
float x1,x2,delta,a,b,c;
printf("\nEnter a:");
scanf("%f",&a);
printf("\nEnter b:");
scanf("%f",&b);
printf("\nEnter c:");
scanf("%f",&c);
/*compute roots*/
delta= b*b-4*a*c;
if(delta==0)
 printf("\n x1=x2=%f",-b/(2*a));
else
if(delta<0)
 printf("\n No root:");
else
{
 x1=  (-b+sqrt(delta))/(2*a);
 x2= (-b-sqrt(delta))/(2*a);
 printf("\nx1=%f , x2=%f",x1,x2);
 }
 getch();
}

هیچ نظری موجود نیست:

ارسال یک نظر