How can we extract the decimal part of a floating point number and store the decimal part and the integer part into two separate integer variables?
Try this:
int main() { double num = 23.345; int intpart = (int)num; double decpart = num - intpart; printf("Num = %f, intpart = %d, decpart = %f\n", num, intpart, decpart); }
For me, it produces:
Num = 23.345000, intpart = 23, decpart = 0.345000
Which appears to be what you're asking for.