13,089,610 members (50,732 online)
Rate this:
See more:
You have to write a computer program that will add 1/3 to itself a large number of times and to compare the result to multiplying 1/3 by the number of times 1/3 was added to itself. It is also to do the same thing with ½.
The program is to do this arithmetic twice, once using single precision (float) and once using double precision (double). Both of these will be in one program. Make certain you use a type for your counter that works with these large numbers.
Your program will do these additions 109 (1 billion) times. It is to print out the results, every power of ten times (10, 100, 1000, etc. up to 1 billion) along with the result of multiplying 1/3 to itself up to that point. Do NOT use fixed point to output the results. Each output should give the power of 10, the result from the addition of 1/3 to itself up to that point, the multiplication of 1/3 times the number of additions, the difference between these last two numbers, the result of adding ½ to itself up to that point, the multiplication of ½ times the number of additions up to that point, and the difference between these last two numbers. The program must output a header before this data explaining what the output is. Remember to do this for both single and double precision.
Make certain to have comments at the beginning of your program with your name, assignment number 3, date, and a brief explanation of the program. Also make certain to put comments within your program. Make certain to properly block the code in your program. Pay attention to the quality of your output, it should not be slopped all over the screen, but be in neat columns (perhaps use \t in the output statements). Remember you are only to do the multiplications when you output, do NOT do them every pass in the loop.
1. Did you notice any difference between the results for ½ and 1/3?
2. Did you notice any difference between the results for single and double precision?
Posted 13-Oct-12 18:47pm
Updated 15-Oct-12 11:26am
v2

Rate this:

## Solution 1

This sounds like homework.

Unfortunately the folks who donate their time to help you in this forum do not look kindly to people who don't bother or are too lazy to do things for themselves.

Homework is for you to learn.

Rate this:

## Solution 2

It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.
Rate this:

## Solution 4

As pointed out, we won't do your homework. but that doesn't mean we won't help at all.

Given this wall of text, I can imagine you feel intimdated and have trouble getting started. I suggest you focus on each paragraph individually, make sure you can get the instructions to work in a computer program, and only continue with the following paragraph if you're sure you're done with the previous.

That said, some of the instructions - specifically the first paragraph - are hard to understand. The main goal of this homework is to understand the effect of rounding errors, and the limits of machine precision. I'll reformulate the task - maybe you will have an easier time understanding this:

Summary
Write a program that calculates some values using repeated addition or multiplication, and print the results. Try different operands, and different variable types, and compare the effects of these choices.

Instructions
1.a) Add the value 1/3 for 100 times, using variables of type `float`
1.b) print the result of the addition after 10 and after 100 additions
2. Multiply the value 1/3 by 10, and by 100, using variables of type `float`, and print these results
3.a) Add the value 1/2 for 100 times using `float`
3.b) print the result of the addition after 10 and after 100 additions
4. Multiply 1/2 by 10 and by 100 using `float`, and print that
5.a) Add 1/3 for 1000000000 times, using variables of type `double`
5.b) print the results after 10, 100, 1000, ... , 1000000000 additions
6. Calculate and print the results of multiplying 1/3 by 10, 100, 1000, ... , 1000000000 .
7.a) and b) and 8.: as above, using a base value of 1/2 instead of 1/3

Try to implement each individual step and make sure it works before continuing.
CPallini 15-Oct-12 6:17am

My 5.
Humberto 15-Oct-12 6:52am

Very instructive. My 5!
Nelek 15-Oct-12 17:39pm

Mine as well.
Rate this:

## Solution 5

This is not a place to do homework. i suggest you to do it for yourself.

try to do it it yourself. i you will face any problem then we will definitely help you.

Top Experts
Last 24hrsThis month
 ProgramFOX 270 Richard Deeming 220 Jochen Arndt 160 OriginalGriff 149 Graeme_Grant 145
 OriginalGriff 3,392 Graeme_Grant 1,784 ProgramFOX 1,697 Jochen Arndt 1,645 ppolymorphe 1,457