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-56 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 6.0 C- 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: d=√b² - 4ac -b+d rootl= a = 1.0 b= -10.0001 C= 25.0005 2a -b-d 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.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter9: Completing The Basics
Section9.5: Input Data Validation
Problem 1E
icon
Related questions
Question
100%
Plz answer Q2 using c programming. include: #include And Printf and scanf
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
root1= 3.000000
root2 = 2.000000
Try your program on twice using the values:
case 1:
case 2:
1.0
b=-5.0
a-
C-
6.0
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:
d = √b² - 4ac
-b+d
rootl=
1.0
b= -10.0001
C= 25.0005
2a
-b-d
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.
Transcribed Image Text: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 root1= 3.000000 root2 = 2.000000 Try your program on twice using the values: case 1: case 2: 1.0 b=-5.0 a- C- 6.0 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: d = √b² - 4ac -b+d rootl= 1.0 b= -10.0001 C= 25.0005 2a -b-d 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.
Expert Solution
steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr