nikolas_serafini

Lista 6 - Exercício 9

Aug 9th, 2013
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define MAXEQ 50
  4.  
  5.  
  6. typedef struct equation {
  7.     float secondDegree,firstDegree,noDegree;
  8. }equation;
  9.  
  10.  
  11. int main() {
  12.  
  13.     int i,currentSize = 0;
  14.     float delta,fRoot,sRoot;
  15.     char c;
  16.     struct equation Equations[MAXEQ];
  17.  
  18.     while(1) {
  19.         printf("Entre com o coeficiente de segundo grau da equacao :\n");
  20.         scanf("%f",&Equations[currentSize].secondDegree);
  21.         printf("Entre com o coeficiente de primeiro grau da equacao :\n");
  22.         scanf("%f",&Equations[currentSize].firstDegree);
  23.         printf("Entre com o elemento independente da equacao:\n");
  24.         scanf("%f",&Equations[currentSize].noDegree);
  25.         currentSize++;
  26.        
  27.         fflush(stdin);
  28.         printf("Deseja inserir mais equacoes? (S/N)\n");
  29.         if (c = getchar() == 'S')
  30.             continue;
  31.         else
  32.             break;
  33.     }
  34.  
  35.     for (i = 0; i < currentSize; i++)
  36.     {
  37.         printf("Equacao : %.2fx^2 + %.2fx + %.2f \n",Equations[i].secondDegree,Equations[i].firstDegree,Equations[i].noDegree);
  38.         delta = pow(Equations[i].firstDegree,2) - 4*Equations[i].secondDegree*Equations[i].noDegree;
  39.         if (delta < 0)
  40.             printf("Nao possui raizes reais!\n");
  41.         else {
  42.             fRoot = (-Equations[i].firstDegree + sqrt(delta)) / 2*Equations[i].secondDegree;
  43.             sRoot = (-Equations[i].firstDegree - sqrt(delta)) / 2*Equations[i].secondDegree;
  44.             printf("Raiz 1 = %.2f\nRaiz 2 = %.2f\n",fRoot,sRoot);
  45.         }
  46.     }
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment