/* How to write and call a Gauss function in C. */ #include <stdio.h> #include <math.h> double x,y; double gauss(x, u, sd) /* Gauss Function Declaration */ double x, u, sd; { double c, TEMP; c = 1.0 / (sd * sqrt(2.0 * 3.14159)); TEMP = x - u; return (c * exp(TEMP * TEMP / (-2.0 * sd * sd))); } /* End of Gauss function */ main() { /* Declaration Statements */ int i; printf("C68.C -> This program implements a Gauss function call in C\n\n"); /* Assignment Statements */ for(i=0 ; i<=10 ; i=i++) { y = 5.0 * gauss(x, 0.0, 1.0) + 2.5; /* Call of Gauss function */ /* Print result */ printf("% .5E % .5E\n",x,y); x = x + 0.5; /* Increase x by 0.5 for each loop */ } /* End of for{} loop */ return(0); } /* End of main Program C68 */ /*OUTPUT :
C68.C -> This program implements a Gauss function call in C 0.0000E+00 4.4947E+00 5.0000E-01 4.2603E+00 1.0000E+00 3.7099E+00 1.5000E+00 3.1476E+00 2.0000E+00 2.7700E+00 2.5000E+00 2.5876E+00 3.0000E+00 2.5222E+00 3.5000E+00 2.5044E+00 4.0000E+00 2.5007E+00 4.5000E+00 2.5001E+00 5.0000E+00 2.5000E+00 */
Last modified: 22/07/97