Created
February 6, 2013 03:12
-
-
Save josefsalyer/4719924 to your computer and use it in GitHub Desktop.
I split out the modf call into it's own line so you can more clearly see what it's doing - splitting the double at the decimal point.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.c | |
// Back to Math classes | |
// | |
// Created by Curt on 2/5/13. | |
// Copyright (c) 2013 Curt. All rights reserved. | |
// | |
#include <stdio.h> | |
#include <math.h> | |
int main(int argc, const char * argv[]) | |
{ | |
//here's a trick - you can assign other names to *point* to x <--notice I used the word POINT (as in, pointer) | |
double x = 3.453, fractional, integer; //so this means that x = 3.453, x= fractional AND x = integer | |
int z = 125; | |
double i = 2.354; | |
//pull out your math into a separate line | |
fractional = modf(x, &integer); // notice the & symbol? that's a reference to x | |
printf("The fractional expression of %.3f is %.3f\n", x, fractional); | |
printf("The integer expression of %.3f is %.3f\n", x, integer); | |
printf ("The cube root of z is %f\n" , cbrt(z)); | |
printf ("The maximum value of x and i is %f\n" , fmax(x,i)); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment