The assignment is 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.
#include<iostream>
#include<conio.h>
#include<math.h>
#include <limits>
using namespace std;
typedef std::numeric_limits< double > dbl;
int main()
{
long size=1000000000;
int count=0;
long N=10;
float nAdd=1;
float nMul=1;
cout.precision(dbl::digits10);
cout<<"Iterration #\t\tAdd\t\t\tMul"<<endl;
for(long i=1; i<=size; i++)
{
nAdd+=1.0/3.0;
nMul*=1.0/3.0;
count++;
if(count%N==0 && count!=0)
{
N*=10;
cout<<i<<"\t\t"<<fixed <<nAdd<<"\t\t"<<fixed <<nMul<<endl;
}
if(count==size)
{
cout<<"Difference : "<<fixed <<nAdd<<" - "<<fixed <<nMul<<" = "<<fixed <<nAdd-nMul<<endl;
}
}
getch();
return 0;
}
so for i have done this
i don't get it properly
what number i have to use which will be multiply by 1/3 or 1/3 will be added into it
can you guyz explain me this a lil
thanks alot