C examples for Function:Function Definition
Create a function called larger_of(x,y) to reset both x and y to the larger of the two.
#include <stdio.h> void larger_of(double *p1, double *p2); int main(void) { //from www . j a v a 2 s.co m double x, y; printf("Enter two numbers (q to quit): "); while (scanf("%lf %lf", &x, &y) == 2) { larger_of(&x, &y); printf("The modified values are %f and %f.\n", x, y); printf("Next two values (q to quit): "); } printf("Bye!\n"); return 0; } void larger_of(double *p1, double *p2) { if (*p1 > *p2) *p2 = *p1; else *p1 = *p2; }