1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| #include <math.h>
#include <stdio.h>
#include <allegro.h>
#include <stdlib.h>
#define VER "3.2"
static int delta (int a, int b, int c)
{
return b * b - (4 * a * c);
}
static double reel (int a, int b, int d, int t)
{
if (t == 1)
{
return (-b + sqrt (d)) / (2 * a);
}
else
{
return (-b - sqrt (d)) / (2 * a);
}
}
static double imaginaire (int a, int b, int d, int t)
{
double xz, xzi;
xz = -b; /*partie reel de la solution */
xz = xz / (2 * a);
xzi = sqrt (-d) / (2 * a); /*partie imaginaire de la solution */
if (t == 1)
{
return xz;
}
else
{
return xzi;
}
}
int main()
{
allegro_init();
install_keyboard();
int a, b, c;
double k=-b/2*a;/*solution si delta=0*/
double x,y;/*pour afficher les coordonnees de la fonction y=ax²+bx+c*/
printf ("\nResolution d'equation du second degre " VER "\n");
printf ("\nVeuillez entrer une valeur pour a,\na= ");
scanf ("%d", &a);
printf ("\nVeuillez entrer une valeur pour b,\nb= ");
scanf ("%d", &b);
printf ("\nVeuillez entrer une valeur pour c,\nc= ");
scanf ("%d", &c);
/* calcul du delta */
int const f = 1;
int const g = 3;
int d = delta (a, b, c);
printf ("\ndelta=%d\n", d);
if (d > 0)
{
printf ("\ndelta est positif et il y a donc 2 solutions reel\n");
printf ("\n"
"solution1 : %.2f\n\n"
"solution2 : %.2f\n"
,reel (a, b, d, f)
,reel (a, b, d, g));
}
if (d<0)
{
printf ("\ndelta est negatif et il y a donc 2 solutions complexe\n");
printf ("\n"
"solution1 : %.2f + %.2f i\n\n"
"solution2 : %.2f - %.2f i\n"
,imaginaire (a, b, d, f)
,imaginaire (a, b, d, g)
,imaginaire (a, b, d, f)
,imaginaire (a, b, d, g));
}
if(d==0)
{
printf("il y a une solution: %f\n",k);
}
system("pause");
set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);
textprintf(screen,font,10,10,10,"voici le graph de la fonction:y=%dx²+%dx+%d",a,b,c);
textout(screen,font,"pressez n'importe quelle touche pour quitter",150,430,13);
hline(screen,100,240,540,12);
vline(screen,320,60,420,12);
textout(screen,font,"x",545,238,13);
textout(screen,font,"Y",320,50,13);
for(x=-50.00,x<=50,x++){
y=a*(x*x)+b*x+c;
putpixel(screen,x,y,12);}
readkey();
exit(EXIT_SUCCESS);
}
END_OF_MAIN(); |
Partager