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.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section: Chapter Questions
Problem 8PP: (Statistical) In many statistical analysis programs, data values considerably outside the range of...
Question
100%
Could you plz use c programming, and 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
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);

    return 0;

steps

Step by step

Solved in 2 steps with 1 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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L