2. When floating point numbers (i.e. float) are added in C, round- off errors can occur if the numbers differ by more than 7 significant digits. To illustrate this round-off problem, write a program to use the quadratic formula to solve ar²+bx+c=0 for read-in values of a, b, and c. This program must use the data type float throughout. Your program input/output should look like: Enter the three coefficients: 1 -5 6 a 1.000000 b=-5.000000 c= 6.000000 rootl= 3.000000 root2 = 2.000000 Try your program on twice using the values: case 1: case 2: a = 1.0 b=-5.0 C= 6.0 d = √√b² - 4ac -b+d rootl= 1.0 b-10.0001 2a -b-d a= In case 1 you should get the roots to be 2.0 and 3.0. In case 2 there will be precision problems and the estimated roots will be near but not equal to the true roots of 5.0000 and 5.0001. Recall that the quadratic formula can be computed in three equations: C= 25.0005 root2 = 2a In your program you must use these formulas in this order to illustrate the round-off problem. 3. Modify your program in question 2 to use the data type double rather than float. Run your program for the same cases and comment on the accuracy in your output.
2. When floating point numbers (i.e. float) are added in C, round- off errors can occur if the numbers differ by more than 7 significant digits. To illustrate this round-off problem, write a program to use the quadratic formula to solve ar²+bx+c=0 for read-in values of a, b, and c. This program must use the data type float throughout. Your program input/output should look like: Enter the three coefficients: 1 -5 6 a 1.000000 b=-5.000000 c= 6.000000 rootl= 3.000000 root2 = 2.000000 Try your program on twice using the values: case 1: case 2: a = 1.0 b=-5.0 C= 6.0 d = √√b² - 4ac -b+d rootl= 1.0 b-10.0001 2a -b-d a= In case 1 you should get the roots to be 2.0 and 3.0. In case 2 there will be precision problems and the estimated roots will be near but not equal to the true roots of 5.0000 and 5.0001. Recall that the quadratic formula can be computed in three equations: C= 25.0005 root2 = 2a In your program you must use these formulas in this order to illustrate the round-off problem. 3. Modify your program in question 2 to use the data type double rather than float. Run your program for the same cases and comment on the accuracy in your output.
2. When floating point numbers (i.e. float) are added in C, round- off errors can occur if the numbers differ by more than 7 significant digits. To illustrate this round-off problem, write a program to use the quadratic formula to solve ar²+bx+c=0 for read-in values of a, b, and c. This program must use the data type float throughout. Your program input/output should look like: Enter the three coefficients: 1 -5 6 a 1.000000 b=-5.000000 c= 6.000000 rootl= 3.000000 root2 = 2.000000 Try your program on twice using the values: case 1: case 2: a = 1.0 b=-5.0 C= 6.0 d = √√b² - 4ac -b+d rootl= 1.0 b-10.0001 2a -b-d a= In case 1 you should get the roots to be 2.0 and 3.0. In case 2 there will be precision problems and the estimated roots will be near but not equal to the true roots of 5.0000 and 5.0001. Recall that the quadratic formula can be computed in three equations: C= 25.0005 root2 = 2a In your program you must use these formulas in this order to illustrate the round-off problem. 3. Modify your program in question 2 to use the data type double rather than float. Run your program for the same cases and comment on the accuracy in your output.
Could you plz use c programming, and include:
include
And printf and scanf
Process by which instructions are given to a computer, software program, or application using code.
Expert Solution
Step 1
I will be provide answers question 3):-
// C program to find roots using double datatype #include <stdio.h> #include<math.h> int main() { // To declare coefficients x,y and z of double datatype double x,y,z;
printf("Enter the three coefficients: "); // the user inputs and store it in x,y and z scanf("%lf%lf%lf",&x,&y,&z); // initialise variable d of double datatype to store discriminant using formula double d= (y*y)-(4*x*z);
// To perform square root using sqrt() function present in math.h d=sqrt(d);
// To declare variable roots1 and store first root double roots1=(-y+d)/(2*x); // declare variable roots2 to store second root double roots2=(-y-d)/(2*x); // print roots1 and roots2 printf("roots1=%lf roots2=%lf",roots1,roots2);
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.