Advertisement
GonzaSurf

Exer 10 b

May 21st, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <conio.h>
  5. int main()
  6. {
  7.     float valor_a = 4;
  8.     float valor_b = 2;
  9.     float valor_c = 9;
  10.     float discriminante = 0;
  11.     float x1 = 0;
  12.     float x2 = 0;
  13.     float xr = 0;
  14.     float xi = 0;
  15.     char variable;
  16.  
  17.     /* Ingreso de datos */
  18.  
  19.     printf("Ingrese un valor para A.\n");
  20.     scanf("%f",&valor_a);
  21.     //variable = getchar();
  22.     //variable = valor_a;
  23.     /*if (variable == 27){
  24.         printf("Cerraste el programa.\n");}*/
  25.     printf("Ingrese un valor para B.\n");
  26.     scanf("%f",&valor_b);
  27.     //variable = getchar();
  28.     /*if (variable == 27){
  29.         printf("Cerraste el programa.\n");}*/
  30.     printf("Ingrese un valor para C.\n");
  31.     scanf("%f",&valor_c);
  32.     //variable = getchar();
  33.     /*if (variable == 27){
  34.         printf("Cerraste el programa.\n");}*/
  35.  
  36.     /* Calculo de discriminante */
  37.  
  38.     discriminante = ((valor_b * valor_b) - (4 * valor_a * valor_c));
  39.     printf("Valor de discriminante %2.1f\n",discriminante);
  40.  
  41.     /* Condicionales */
  42.  
  43.     if (discriminante > 0.0){
  44.         x1 = (- valor_b + sqrt(discriminante)) / (2 * valor_a);
  45.         x2 = (- valor_b - sqrt(discriminante)) / (2 * valor_a);
  46.         printf("Las dos raices son reales y distintas.\n");
  47.         printf("x1 = %2.1f\n",x1);
  48.         printf("x2 = %2.1f\n",x2);
  49.     } else if (discriminante == 0.0){
  50.         x1 = x2 = (- valor_b / 2 * valor_a);
  51.         printf("Las dos raices son  reales e iguales.\n");
  52.         printf("Raices = %2.1f\n",x1);
  53.     } else if (discriminante < 0.0) {
  54.         xr = (- valor_b / 2 * valor_a);
  55.         xi = (sqrt(-discriminante) / 2 * valor_a);
  56.         printf("Las dos raices son complejas conjugadas.\n");
  57.         printf("Valor real = %2.1f\n",xr);
  58.         printf("Valor imaginario = %2.1f\n",xi);
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement