Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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.
Items to think about:
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
Edited 15-Oct-12 11:26am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

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.
  Permalink  
Comments
CPallini at 15-Oct-12 6:17am
   
My 5.
Humberto at 15-Oct-12 6:52am
   
Very instructive. My 5!
Nelek at 15-Oct-12 17:39pm
   
Mine as well.
Rate this: bad
good
Please Sign up or sign in to vote.

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.
 
Please respect the time of others and ask genuine questions.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

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.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 716
1 OriginalGriff 442
2 Tadit Dash 400
3 sanket saxena 337
4 Peter Leow 228
0 Sergey Alexandrovich Kryukov 11,890
1 OriginalGriff 7,335
2 Peter Leow 5,003
3 Abhinav S 3,943
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web04 | 2.8.140421.2 | Last Updated 16 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid