# كود حل معادلة من الدرجة الثانية بأدخال ثوابتها وذلك بلغة C تحياتي ... by;-Saif GaRa

(eng.GaRa) #1

برنامج حل معادلة من الدرجة الثانية وايجاد حلولها وهي من الشكل
" Ax^2 + Bx + c = 0 "
بلغة الـ C بكافة حالاتها …

``````
[SIZE=4]#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char **argv[])
{
float a=0,b=0,c=0,delta=0;
float x1=0,x2=0;
char k;

printf("
WE ARE GOING To SOLVE THE EQUATION :
");
printf("
ax^2+bx+c=0

delta=b^2+4ac

");
printf("
x1=(-b-sqrt(delta))/(2*a)

x2=(-b+sqrt(delta))/(2*a)

");
printf("***********************************************************************

");
printf("	 a= ");
scanf("%f",&a);
printf("
b= ");
scanf("%f",&b);
printf("
c= ");
scanf("%f",&c);
printf("

***********************************************************************

");

if(a==0)
{
if(b==0)
{
if(c==0)
printf("ROOT IS ANT VALUE!!!");
else
printf("IT IS IMPOSIBUL!!!");
}
else
if(c==0)
printf("
%2.2fx=0
ROOT IS x=0",b);
else
{
printf("%2.2fx+%2.2f=0",b,c);
x1=-c/b;
printf("
ROOT IS x=%2.2f",x1);
}

}
else
if(b==0)
{
if(c==0)
{
printf("
%2.2fx^2
ROOT ISx=0",a);
}
else
if(  ( (c<0)&&(a>0) )||( (c>0)&&(a<0) )  )
{
printf("
%2.2x^2+%2.2f=0",a,c);
x1=sqrt(-c/b);
printf("

ROOTS ARE x1=%2.2f	x2=%2.2f",x1,x2);
}
else
printf("
WE CAN NOT SOLVE IT IN REAL SPASE!!!
");

}
else
if (c==0)
{
printf(" %2.2fx^2 + %2.2fx =0",a,b);
x1=0;
x2=-b/a;
printf("
x1=%2.2f	x2=%2.2f
",x1,x2);
}
else
{
printf("%2.2x^2+%2.2fx+%2.2f=0",a,b,c);
delta=pow(b,2)-4*a*c;
if(delta>0)
{
x1=(-b+sqrt(delta))/(2*a);
x2=(-b-sqrt(delta))/(2*a);
printf("

delta=%2.2f

WE HAVE TWO ROOTS:

x1=%2.2f	x2=%2.2f
",delta,x1,x2);
}
else
if(delta==0)
{
x1=-b/(2*a);
printf("

delta=%2.2f

ROOTS ARE: x1=x2=%2.2f",delta,x1);
}
else
if(delta<0)
printf("

delta = %2.2f

WE CAN NOT SOLVE IT IN REAL SPASE!!!
",delta);
}
printf("

");
printf("*********************************END***********************************

");
printf("			//by jonior eng.GaRa//

");

system("PAUSE");
return 0;
}
[/size]

``````

تحياتي اصدقائي