5. When floating point numbers (i.e. float) are added in C round off errors can occur if the numbers differ by more than
Posted: Mon Jul 11, 2022 9:57 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 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.