25 lines
479 B
C
25 lines
479 B
C
|
/* decompose.c
|
||
|
*
|
||
|
* Demonstrates use of passing and using pointers to/in a function.
|
||
|
*/
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
void decompose(double x, long* int_part, double* frac_part);
|
||
|
int main()
|
||
|
{
|
||
|
long i;
|
||
|
double d;
|
||
|
double pie = 3.14159f;
|
||
|
decompose(pie, &i, &d);
|
||
|
|
||
|
printf("Decomposed values for %lf: %ld, %lf\n", pie, i, d);
|
||
|
|
||
|
return EXIT_SUCCESS;
|
||
|
}
|
||
|
|
||
|
void decompose(double x, long* int_part, double*frac_part){
|
||
|
*int_part = (long) x;
|
||
|
*frac_part = x - *int_part;
|
||
|
}
|