Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <conio.h>
- int main()
- {
- float valor_a = 4;
- float valor_b = 2;
- float valor_c = 9;
- float discriminante = 0;
- float x1 = 0;
- float x2 = 0;
- float xr = 0;
- float xi = 0;
- char variable;
- /* Ingreso de datos */
- printf("Ingrese un valor para A.\n");
- scanf("%f",&valor_a);
- //variable = getchar();
- //variable = valor_a;
- /*if (variable == 27){
- printf("Cerraste el programa.\n");}*/
- printf("Ingrese un valor para B.\n");
- scanf("%f",&valor_b);
- //variable = getchar();
- /*if (variable == 27){
- printf("Cerraste el programa.\n");}*/
- printf("Ingrese un valor para C.\n");
- scanf("%f",&valor_c);
- //variable = getchar();
- /*if (variable == 27){
- printf("Cerraste el programa.\n");}*/
- /* Calculo de discriminante */
- discriminante = ((valor_b * valor_b) - (4 * valor_a * valor_c));
- printf("Valor de discriminante %2.1f\n",discriminante);
- /* Condicionales */
- if (discriminante > 0.0){
- x1 = (- valor_b + sqrt(discriminante)) / (2 * valor_a);
- x2 = (- valor_b - sqrt(discriminante)) / (2 * valor_a);
- printf("Las dos raices son reales y distintas.\n");
- printf("x1 = %2.1f\n",x1);
- printf("x2 = %2.1f\n",x2);
- } else if (discriminante == 0.0){
- x1 = x2 = (- valor_b / 2 * valor_a);
- printf("Las dos raices son reales e iguales.\n");
- printf("Raices = %2.1f\n",x1);
- } else if (discriminante < 0.0) {
- xr = (- valor_b / 2 * valor_a);
- xi = (sqrt(-discriminante) / 2 * valor_a);
- printf("Las dos raices son complejas conjugadas.\n");
- printf("Valor real = %2.1f\n",xr);
- printf("Valor imaginario = %2.1f\n",xi);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement