#include #include #include void split (double number, char* sign, int *whole, double *fraction) { /* This function has pointers as parameters. The function cannot change values of variables provided by "main" as arguments. But it can change variables at addresses pointed to by "sign", "whole" and "fraction" */ if (number < 0) *sign = '-'; else if (number > 0) *sign = '+'; else *sign = ' '; *whole = abs ((int)number); *fraction = fabs (number) - *whole; } int main (void) { double n, f; int w; char s; printf ("Enter a double number to split:"); scanf ("%lf", &n); /* See that when a parameter is a pointer, you must send an address of a variable to it. Because "split" function gets addresses of variables, it can modify variables themselves. */ split (n, &s, &w, &f); printf ("The sign is: %c\n", s); printf ("The whole part is: %d\n", w); printf ("The fraction is: %lf\n", f); return (0); }