Linear Algebra and the C Language/a0e7
Install and compile this file in your working directory.
/* ------------------------------------ */
/* Save as : c00c.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------
positive and negative numbers
------------------------------------ */
int X_r_I(
int maxI)
{
int x;
x = (rand() % maxI) + 1; /* + 1 : not zero */
x *= pow(-1,rand()); /* signe + or - */
return(x);
}
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
do{
clrscrn();
printf("random numbers (p for positive numbers) \n\n");
printf(" r_I(9) : [-9,9] x = %+d \n", r_I(9));
printf("rp_I(9) : [ 1,9] x = %+d \n\n", rp_I(9));
printf("random numbers (0 for with zero) \n\n");
printf(" r0_I(9) : [-9,9] x = %+d \n", r0_I(9));
printf("rp0_I(9) : [ 0,9] x = %+d \n",rp0_I(9));
}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:
random numbers (p for positive numbers)
r_I(9) : [-9,9] x = +1
rp_I(9) : [ 1,9] x = +5
random numbers (0 for with zero)
r0_I(9) : [-9,9] x = +2
rp0_I(9) : [ 0,9] x = +2
Press return to continue
Press X return to stop