Linear Algebra and the C Language/a0e8
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as : c00d.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------
Positive and negative floating point number
e= 1E-0 -> 1234
e = 1E-1 -> 123.4
e = 1E-2 -> 12.34
e = 1E-3 -> 1.234
------------------------------------ */
double X_r_E(
int maxI,
double e)
{
double x;
x = (rand() % maxI) + 1 ; /* + 1 : not zero */
x *= pow(-1,rand()) * e; /* sign + or - */
return(x);
}
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
do{
clrscrn();
printf(" Decimal numbers: \n");
printf(" r_E(999, 1e-3): %+0.3f\n\n\n", r_E(999, 1e-3));
printf(" Scientific Notation : %%+0.3E ... \%%+0.3e \n\n");
printf(" Positive and negative numbers: \n");
printf(" r_E(999, 1e-3): %+0.3e \n", r_E(999, 1e-3));
printf(" r_E(999, 1E+3): %+0.3E\n\n\n", r_E(999, 1E+3));
printf(" Positive numbers: \n");
printf(" rp_E(999, 1e-3): %+0.3e \n", rp_E(999, 1e-3));
printf(" rp_E(999, 1E+3): %+0.3E\n\n\n", rp_E(999, 1E+3));
}while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
I rename the function studied with the prefix X_ to differentiate it from the one with the same name in the library.
Screen output example:
Decimal numbers:
r_E(999, 1e-3): +0.183
Scientific Notation : %+0.3E ... %+0.3e
Positive and negative numbers:
r_E(999, 1e-3): -4.940e-01
r_E(999, 1E+3): +8.880E+05
Positive numbers:
rp_E(999, 1e-3): +8.070e-01
rp_E(999, 1E+3): +8.360E+05
Press return to continue
Press X return to stop