Aller au contenu

Mathc complexes/Fichiers c : test01c

Un livre de Wikilivres.


Utilitaires

Installer et compiler ce fichier dans votre répertoire de travail.

c00d.c
/* ------------------------------------ */
/*  Save as :   c00d.c                  */
/* ------------------------------------ */
#include "w_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\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(" r_E(999, 1e-3):  %+0.3e  \n", r_E(999, 1e-3));
 printf(" r_E(999, 1E+3):  %+0.3E  \n", r_E(999, 1E+3));
 
    }while(stop_w());
		
  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */

Exemple de sortie écran :

 Decimal numbers: 

 r_E(999, 1e-3):  -0.556


 Scientific Notation :     %+0.3E ... %+0.3e 

 r_E(999, 1e-3):  -2.860e-01  
 r_E(999, 1E+3):  +4.370E+05  

 Press   return to continue
 Press X return to stop