IHYPRESS.NET > C PROGRAMMING
HOME | CLASSIC ASP | C | HTML/CSS | JAVASCRIPT | PERL | PHP | PYTHON | RUBY
C > 06. Functions II (Pointers) [PROGRAM #01]
CODERESULT
 
/* Problem: This program shows a function that generates two results. 
One result is returned (-), the other accessed from the main via an address (+). */



#include <stdio.h>
#include <math.h>

double
quadratic (int a, int b, int c, double* xplus)
{
	double xminus;

	xminus  = (-b - sqrt (b * b - 4 * a * c))/ (2 * a);
	*xplus  = (-b + sqrt (b * b - 4 * a * c))/ (2 * a);
	return (xminus);
}


int
main (void)
{
	int a = 10, b = 40, c = 30;
	double xplus, xminus;

	/* calling the function. the address of xplus is sent as an argument */
	xminus = quadratic (a, b, c, &xplus);
	
	printf ("Using +: %lf\n", xplus);
	printf ("Using -: %lf\n", xminus);

	return (0);
}
Legend: preprocessor directives | variable declarations main function | helper functions | user-defined structures comments
Using +: -1.000000
Using -: -3.000000
>
COPYRIGHT © 2021 IHYPRESS.NET. A DIVISION OF IHY PRESS, KIRKLAND, WA 98083 USA. ALL RIGHTS RESERVED.