IHYPRESS.NET
C
HOME | ASP | C | CSS | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
CAdvanced Functions ❯ Multiple Results
<06.06>
/* This function takes a real number and separates it */ /* into three parts: a sign (a character value), a */ /* whole part (an integer) and a fraction (double) */ #include <stdio.h> #include <math.h> /* the function returns the sign but the pointer parameters */ /* will modifiy the corresponding variable arguments in */ /* main program */ char separate (double number, int *w, double *f) { char s; double magnitude; /* the absolute value of the number */ /* testing if positive or negative and assignation of sign */ if (number < 0) s = '-'; else if (number == 0) s = ' '; else s = '+'; magnitude = fabs (number); *w = floor (magnitude); *f = magnitude - *w; return (s); } int main (void) { double n; /* the original number */ /* the variables that will be filled by the function */ char sign; int whole; double fraction; printf ("Enter a real number: "); scanf ("%lf", &n); /* calling the function */ sign = separate (n, &whole, &fraction); /* printing the report */ printf ("Parts of %f: \n", n); printf ("===============\n\n"); printf ("Sign is: %c \n", sign); printf ("Whole part is %d \n", whole); printf ("Fraction part is %f \n", fraction); return (0); }
Hergestellt in Deutschland / Made in Germany
Enter a real number: -46.73 Parts of -46.730000: =============== Sign is: - Whole part is 46 Fraction part is 0.730000
COPYRIGHT © 2015-2024 IHYPRESS.NET. A DIVISION OF IHY PRESS. ALL RIGHTS RESERVED.