IHYPRESS.NET > C PROGRAMMING
HOME | CLASSIC ASP | C | HTML/CSS | JAVASCRIPT | PERL | PHP | PYTHON | RUBY
C > 06. Functions II (Pointers) [PROGRAM #05]
CODERESULT
<
/* Problem: Write a function that takes in an integer number and
"returns" both twice the number and three times the number. */

#include <stdio.h>

/* double_triple function begins */
int
double_triple (int x, int *d)
{
	int t;
	*d=2*x; /* double "returned" via pointer */
	t=3*x;
	return (t); /* triple returned the standard way */
}
/* double_triple function ends */



/* main program begins */
int
main(void)
{

	int a,twice,thrice;
	a=10;
	thrice = double_triple (a, &twice);
	printf("%d is two times %d.\n",twice,a);
	printf("%d is three times %d.\n",thrice,a);

	return(0);
}
/* main program ends */


Legend: preprocessor directives | variable declarations main function | helper functions | user-defined structures comments
20 is two times 10.
30 is three times 10.
>
COPYRIGHT © 2021 IHYPRESS.NET. A DIVISION OF IHY PRESS, KIRKLAND, WA 98083 USA. ALL RIGHTS RESERVED.