Reference no: EM132360857
Question :
Create a program to create a program that adds the numbers 1/2 to itself and 1/3 to itself a large number of times. It is to then compare the values of adding the numbers to multiplying 1/2 and 1/3 times the number of times they were added. The program must first add 1/2 and 1/3, 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. When the inner loop completes, output the two sums (the ½ and the 1/3) and the two products, and the differences and continue the outer loop. Remember to clear your variables for the sums (accumulators) before the start of the inner loop.
The output should look something like this:
The columns below are:
Iterations, 1/2 sum, 1/2 product, diff, 1/3 sum, 1/3 product, diff
1000 500.0 500.0 0.0 333.33333333333184 333.3333333333333 -1.4779288903810084e-12