5. When floating point numbers (i.e. float) are added in C round off errors can occur if the numbers differ by more than

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

5. When floating point numbers (i.e. float) are added in C round off errors can occur if the numbers differ by more than

Post by answerhappygod »

5 When Floating Point Numbers I E Float Are Added In C Round Off Errors Can Occur If The Numbers Differ By More Than 1
5 When Floating Point Numbers I E Float Are Added In C Round Off Errors Can Occur If The Numbers Differ By More Than 1 (42.96 KiB) Viewed 26 times
5&6 USING C LANGUAGE ONLY!
5. 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. For example, if a = 100,000,000 and b = 1 then c = a + b will differ from its exact value. Write a program to illustrate this. Your program should prompt the user for two numbers and then compute and print the sum and should look like: Enter a number: 100000000 Enter another number which is significantly smaller: 11 The sum of 100000000.000000 and 1.000000 is 100000000.000000 /* File: roundoff.c */ Shows the problems with roundoffs Programmer: #include <stdio.h> int main(void) { /* you fill in here */ return 0; Date: } For marking purposes, run the program twice, once with the values above, and again with a 7500 and b=0.00025. As before, copy and paste your program and its output into the solutions1.txt. 6. Repeat the previous question, but change the floating point variables to doubles to create a new program and run your program again with both sets of values. Remember to use %lf as the scanf format when reading doubles. As before, copy and paste your program and its output into the solutions1.txt.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply