# Answer to Question #10867 in C++ for Jo

Question #10867

The program below (in C not in C++) reads a double before calling the chop function, which has

the following prototype:

void chop(double d, long *whole_part, double *fraction_part);

This function chops the double into two parts, the whole part and the fraction.

So “365.25” would be chopped into “365” and “.25”. Implement the function.

#include <stdio.h>

#include <math.h>

#include <limits.h>

void chop(double d, long *whole_part, double *fraction_part);

int main(void)

{

double d = 0.0;

long whole = 0;

double fraction = 0.0;

printf("enter a double ");

scanf("%lf", &d);

chop(d, &whole, &fraction);

printf("%lf chopped is %ld and %.5lg\n",

d, whole, fraction);

return 0;

}

void chop(double d, long *whole_part, double *fraction_part)

{

Insert the function here

}

the following prototype:

void chop(double d, long *whole_part, double *fraction_part);

This function chops the double into two parts, the whole part and the fraction.

So “365.25” would be chopped into “365” and “.25”. Implement the function.

#include <stdio.h>

#include <math.h>

#include <limits.h>

void chop(double d, long *whole_part, double *fraction_part);

int main(void)

{

double d = 0.0;

long whole = 0;

double fraction = 0.0;

printf("enter a double ");

scanf("%lf", &d);

chop(d, &whole, &fraction);

printf("%lf chopped is %ld and %.5lg\n",

d, whole, fraction);

return 0;

}

void chop(double d, long *whole_part, double *fraction_part)

{

Insert the function here

}

Expert's answer

int main(void)

{

& double d = 1.5;

& double i = 0;

& double f = modf(d, &i);

& printf("Number = %g\n", d);

& printf("Integer part = %g, fractional part = %g\n", i, f);

& return 0;

}

{

& double d = 1.5;

& double i = 0;

& double f = modf(d, &i);

& printf("Number = %g\n", d);

& printf("Integer part = %g, fractional part = %g\n", i, f);

& return 0;

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment