# why is the limits different ?

Discussion in 'C' started by aurnk, Dec 22, 2006.

Not open for further replies.
1. ### aurnkNew Member

Joined:
Dec 13, 2006
Messages:
5
0
Trophy Points:
0
why is the output1 different from output2 ?
why is the output3 different from output4 ?
/*my doubt is
why is the limit of float (note 1) different from the limit of float1 (note 2)?*/
Code:
```#include"fx.h"
#define limit(t) (1*(pow(10,(-(t)))))//1*10^-t
void floatlimit()//this checks when 0.00000000...1==1 for float
{
float i=1.0;int j=1;
for(;i!=0;i/=10,j++);
printf("\nthe limit of float is %d",j);//note 1
}
void doublelimit()//this checks when 0.00000000...1==1 for double
{
double i=1.0;int j=1;
for(;i!=0;i/=10,j++);
printf("\nthe limit of double is %d",j);//note 3
}
void floatlimit1()//this checks when 1.000...1==1 for float
{
float a;int i;
for(a=1.1,i=1;a!=1;++i)
{
a=1+limit(i);
}
printf("\nthe limit of float1 is %d",(i-1));//note 2
}
void doublelimit1()//this checks when 1.000...1==1 for double
{
double a;int i;
for(a=1.1,i=1;a!=1;++i)
{
a=1+limit(i);
}
printf("\nthe limit of double1 is %d",(i-1));//note 4
}
main()
{
void floatlimit();
void floatlimit1();
void doublelimit();
void doublelimit1();
floatlimit();
floatlimit1();
doublelimit();
doublelimit1();
getch();
}```
/*
bloodshed dev C++
pentium 4 processor
*/

Last edited by a moderator: Dec 22, 2006

Joined:
Jul 12, 2004
Messages:
15,326