/************************************************************* * Program to demonstrate the use of functions sinintegral(x) * * or cosintegral(x) using the Simpson's method * * ---------------------------------------------------------- * * SAMPLE RUNS: * * * * Kind (1 or 2): 1 * * * * Test of Function sinintegral(x) by Simpson's method * * * * Input value for x variable: * * * * X = 2 * * * * Result: 1.605412976802747e+000 * * * * X = 5 * * * * Result: 1.549931244944637e+000 * * * * X = 99 * * * * Result: 1.570496064852390e+000 * * * * * * Kind (1 or 2): 2 * * * * Test of Function cosintegral(x) by Simpson's method * * * * Input value for x variable: * * * * X = 2 * * * * Result: 4.229808287748087e-001 * * * * X = 5 * * * * Result: -1.900297496567200e-001 * * * * X = 99 * * * * Result: -1.009500171213582e-002 * * * * C++ version by J-P Moreau. * * (www.jpmoreau.fr) * *************************************************************/ //to link with module sinint.cpp //============================== #include #include double x; // function argument int kind; // =1 for sinintegral, =2 for cosintegral double sinintegral(double); double cosintegral(double); void main() { printf("\n Kind (1 or 2): "); scanf("%d", &kind); if (kind==1) printf("\n Test of Function sinintegral(x) by Simpson's method\n\n"); else printf("\n Test of Function cosintegral(x) by Simpson's method\n\n"); printf("\n Input value for x variable:\n\n"); printf(" X = "); scanf("%lf", &x); if (kind==2 && x<=0.0) printf(" Warning! X must be positive for kind=2.\n"); else if (kind==1) printf("\n\n Result: %21.15e\n\n", sinintegral(x)); else printf("\n\n Result: %21.15e\n\n", cosintegral(x)); } // End of file tsinintegral.cpp