#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
float a, b, c, D, x1, x2, j, x1real, x1imag;
printf("S pomocjo tega programa lahko izracunamo kvadratno enacbo oblike ax^2+bx+c=0\n") ;
printf("vnesi prvo (a) spremenljivko enacbe: \n");
scanf("%f", &a);
printf("vnesi drugo (b) spremenljivko enacbe: \n");
scanf("%f", &b);
printf("vnesi tretjo (c) spremenljivko enacbe: \n");
scanf("%f", &c);
D=(b*b)-(4*a*c);
if(D>=0)
{
x1=((-b+sqrt(D))/(2*a));
x2=((-b-sqrt(D))/(2*a));
printf("Resitvi kvadratne enacbe sta:\n");
printf("x1=%f\n ", x1);
printf("x2=%f\n ", x2);
}
else
{
x1real=-b/2*a;
x1imag=sqrt(D)/2*a;
printf("Rešitve enačbe so:\n");
printf("x1 = %f + i*%f\n",x1real, x1imag);
printf("x1 = %f - i*%f\n",x1real, x1imag);
}
system("PAUSE") ;
return 0;
}
So this is the code I wrote, it is supposed to be a program that solves quadratic equations (don't mind the printf sections with tekst in my language, it's a school asignment..). so aniway, when you run it and you solve an equasion with a negative discriminant the irational part is shown as 1.#IND00.. I get that this is an error that ocurs because the size of the number (places of numeric signs) is too big, but how can I reduce it?
#include <stdlib.h>
#include <math.h>
int main()
{
float a, b, c, D, x1, x2, j, x1real, x1imag;
printf("S pomocjo tega programa lahko izracunamo kvadratno enacbo oblike ax^2+bx+c=0\n") ;
printf("vnesi prvo (a) spremenljivko enacbe: \n");
scanf("%f", &a);
printf("vnesi drugo (b) spremenljivko enacbe: \n");
scanf("%f", &b);
printf("vnesi tretjo (c) spremenljivko enacbe: \n");
scanf("%f", &c);
D=(b*b)-(4*a*c);
if(D>=0)
{
x1=((-b+sqrt(D))/(2*a));
x2=((-b-sqrt(D))/(2*a));
printf("Resitvi kvadratne enacbe sta:\n");
printf("x1=%f\n ", x1);
printf("x2=%f\n ", x2);
}
else
{
x1real=-b/2*a;
x1imag=sqrt(D)/2*a;
printf("Rešitve enačbe so:\n");
printf("x1 = %f + i*%f\n",x1real, x1imag);
printf("x1 = %f - i*%f\n",x1real, x1imag);
}
system("PAUSE") ;
return 0;
}
So this is the code I wrote, it is supposed to be a program that solves quadratic equations (don't mind the printf sections with tekst in my language, it's a school asignment..). so aniway, when you run it and you solve an equasion with a negative discriminant the irational part is shown as 1.#IND00.. I get that this is an error that ocurs because the size of the number (places of numeric signs) is too big, but how can I reduce it?
Comment