CS2263/ForNextDay/Lec6/Lec6src/decompose.c

25 lines
479 B
C
Raw Permalink Normal View History

2023-05-22 23:28:51 -03:00
/* 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;
}