Hey guys I was wondering If it was possible to detect if a number is a decimal like this 5.5 but not an integer. Thanks for the help (sorry if you expecting a longer question )
Hey guys I was wondering If it was possible to detect if a number is a decimal like this 5.5 but not an integer. Thanks for the help (sorry if you expecting a longer question )
And how is this number stored? For example, if it's a string, it's pretty simple: if(strchr('.'))
If you understand what you're doing, you're not learning anything.
There are several ways to do this...
For example you can use the abs() function...
Code:float Num = 5.5; if (abs(Num) != Num) puts"It is not a whole number";
abs() ?
Perhaps floor().
Thanks for the help, I have started with my programming, it will do synthetic division, but I have ran into a slight problem. To be honest I don't know what is happening but I know its in the while loop and when I step through the program on my debugger it just quits when it gets to the while loop. Here is my code...
thanks againCode:#include <stdio.h> #include <math.h> main() { double test; int c; int a; int divide = 0; double cdivide; double pmax; test = 5.5; printf("enter c:"); scanf("%d",&c); printf("\nnow enter a:"); scanf("%d",&a); pmax = 2 / c; while(divide <= pmax) { cdivide = c / divide; if( floor(cdivide) != cdivide) { printf("not an int"); } else { printf("new p found: %d",cdivide); } divide++; } printf("done"); getch(); return 0; }
Quzah.Code:if( (float)((int) f) != f ) print( "Houston, we have a decimal.\n" );
Hope is the first step on the road to disappointment.
modf(3) - Linux man page
No worry about overflow.
Take a close look at your code... what is the value of the divide variable when it gets to the bit above?Code:while(divide <= pmax) { cdivide = c / divide;