Programming in algorithm analysis Implement a program that f
Programming in algorithm analysis
•Implement a program that finds the zero of a function
f(n) = 8n2 – 64n lg n
Solution
#include <stdio.h>
#include <math.h>
int main()
{
double a, b, c, dete, root_1,root_2, rp, ip;
printf(\"Enter coefficients a, b and c: \");
scanf(\"%lf %lf %lf\",&a, &b, &c);
dete = b*b-4*a*c;
// condition for real and different roots
if (dete > 0)
{
// sqrt() function returns square root
root_1 = (-b+sqrt(dete))/(2*a);
root_2 = (-b-sqrt(dete))/(2*a);
printf(\"root_1 = %.2lf and root_2 = %.2lf\",root_1 , root_2);
}
//condition for real and equal roots
else if (dete == 0)
{
root_1 = root_2 = -b/(2*a);
printf(\"root_1 = root_2 = %.2lf;\", root_1);
}
// if roots are not real
else
{
rp = -b/(2*a);
ip = sqrt(-dete)/(2*a);
printf(\"root_1 = %.2lf+%.2lfi and root_2 = %.2f-%.2fi\", rp, ip, rp, ip);
}
return 0;
}
#include <stdio.h>
#include <math.h>
int main()
{
double a, b, c, dete, root_1,root_2, rp, ip;
printf(\"Enter coefficients a, b and c: \");
scanf(\"%lf %lf %lf\",&a, &b, &c);
dete = b*b-4*a*c;
// condition for real and different roots
if (dete > 0)
{
// sqrt() function returns square root
root_1 = (-b+sqrt(dete))/(2*a);
root_2 = (-b-sqrt(dete))/(2*a);
printf(\"root_1 = %.2lf and root_2 = %.2lf\",root_1 , root_2);
}
//condition for real and equal roots
else if (dete == 0)
{
root_1 = root_2 = -b/(2*a);
printf(\"root_1 = root_2 = %.2lf;\", root_1);
}
// if roots are not real
else
{
rp = -b/(2*a);
ip = sqrt(-dete)/(2*a);
printf(\"root_1 = %.2lf+%.2lfi and root_2 = %.2f-%.2fi\", rp, ip, rp, ip);
}
return 0;
}


