Question
Assignment number 2 for Computer Architecture The assignment is to create a program that adds the number 1/2 to itself a large number of times
Assignment number 2 for Computer Architecture The assignment is to create a program that adds the number 1/2 to itself a large number of times and adds the number 1/3 to itself a large number of times separately first using type float and then type double. It is to then compare the values of adding the numbers to multiplying 1/2 time the number of times added to compute the same sum in a different way. The program will also multiply 1/3 times the number of times 1/3 was added to itself to compute the same sum in a different way. The program will then compare these two methods at arrive for the same value and output the difference. Hint, the value for the s will be the same for the smaller numbers of times, the 1/3s will never be the same. The output from your program is to be to a *.txt file which you are to turn in along with your code. The program must first add the s and 1/3s using type float and compare to the value obtain using multiplication instead of addition. It is to do this for the following values: 1.000 10,000 100,000 1,000,000 10,000,000 100,000,000 1,000,000,000 The program should do this using two nested loops. The outer loop determines the number of times to add and starts at a 1000 and increments by multiples of 10 up to a 1,000,000,000. The inner loop does the addition of the numbers 1/2 and 1/3 (Note, there are to be two sums, one sum is for the s and the other for the 1/3s). When the inner loop finishes, compute the products that should be the same. Hint, they will not always be the same. Why? After the inner loop completes, output the two sums and the two products, and the differences between the sums and the products that should be the same to check for rounding errors. Hint, the s will be good for at least a while, but the 1/3s will always be off since 1/3 does not go into a float (or double) exactly. Then continue the outer loop. Remember to clear your variables for the sums before the start of the inner loop. Send this output to a text file. The top line of the output file should have your name and the assignment number. Next the program repeats the above except that it uses type double instead of type float for the variables. This will require a second set of nested loops and different variables. Have your name, the assignment number, and a brief description of the program in comments at the top, have comments in the program, use proper blocking, and make certain to test your program to verify that it is working properly.
Please use c/c++, and show me the input and output.
thanks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started