/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
printf("Equation du second degré \n");
/*déclaration des variables*/
int a=0, b=0, c=0 ;
int delta = 0;
float x=0, x1=0, x2=0;
//Saisie de a, b et c
printf("RESOLUTION EQUATION 2 DEGRE FORME aX2 + bX + c = 0 \n");
printf("Saisir a \n");
scanf("%d",&a);
printf("Saisir b \n");
scanf("%d",&b);
printf("Saisir c \n");
scanf("%d",&c);
/*calcul de delta*/
delta = b*b - 4*a*c ;
//delta négatif
printf("delta = %d \n", delta);
//delta nul
if (delta == 0) {
x = -b/(2*a);
printf("delta est nul, il y a une seule solution double, x = %.3f\n", x);
}
//delta positif
else if (delta > 0) {
x1 = (-b-sqrt(delta))/(2*a);
x2 = (-b+sqrt(delta))/(2*a);
printf("delta > 0, x1 = %.3f \t x2 = %.3f \n", x1, x2 );
}
//delta < 0
else {
printf("il n'y a pas de solutions dans R\n");
}
return 0;
}