Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define MAXEQ 50
- typedef struct equation {
- float secondDegree,firstDegree,noDegree;
- }equation;
- int main() {
- int i,currentSize = 0;
- float delta,fRoot,sRoot;
- char c;
- struct equation Equations[MAXEQ];
- while(1) {
- printf("Entre com o coeficiente de segundo grau da equacao :\n");
- scanf("%f",&Equations[currentSize].secondDegree);
- printf("Entre com o coeficiente de primeiro grau da equacao :\n");
- scanf("%f",&Equations[currentSize].firstDegree);
- printf("Entre com o elemento independente da equacao:\n");
- scanf("%f",&Equations[currentSize].noDegree);
- currentSize++;
- fflush(stdin);
- printf("Deseja inserir mais equacoes? (S/N)\n");
- if (c = getchar() == 'S')
- continue;
- else
- break;
- }
- for (i = 0; i < currentSize; i++)
- {
- printf("Equacao : %.2fx^2 + %.2fx + %.2f \n",Equations[i].secondDegree,Equations[i].firstDegree,Equations[i].noDegree);
- delta = pow(Equations[i].firstDegree,2) - 4*Equations[i].secondDegree*Equations[i].noDegree;
- if (delta < 0)
- printf("Nao possui raizes reais!\n");
- else {
- fRoot = (-Equations[i].firstDegree + sqrt(delta)) / 2*Equations[i].secondDegree;
- sRoot = (-Equations[i].firstDegree - sqrt(delta)) / 2*Equations[i].secondDegree;
- printf("Raiz 1 = %.2f\nRaiz 2 = %.2f\n",fRoot,sRoot);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment