Aller au contenu

Mathc initiation/Fichiers c : c15h

Un livre de Wikilivres.


Sommaire


Installer et compiler ces fichiers dans votre répertoire de travail.

a08_fun.c
/* ---------------------------------- */
/*  Save as :   a08_fun.c             */
/* ---------------------------------- */
#include    "x_hfile.h"
/* ---------------------------------- */
/* ---------------------------------- */
int main(void)
{
time_t t;

int i=0,j=0,n=1,loop=0;

  srand(time(&t));
  
  
/* ---------------------------------- */
/* ---------------------------------- */
loop=5;  
do{clrscrn();
	
   printf("Addition\n\n\n\n");   
   printf(" i+j: %10d      \n\n",j+i);
   
   j  = rp_I (9000)+999;
   i  = rp_I (9000)+999;
   
   printf("   j: %10d         \n",j    );
   printf("  +i: %10d       (%d)",i,n++);
   
   nlign(6);   
   stop();

}while(n<=loop);

   clrscrn();
   printf("Addition\n\n\n\n");
   printf("  %d + %d = %d     (%d)\n",i,j,j+i,--n);    
   nlign(6);    
   stop();
/* ---------------------------------- */
loop=5;
i=0,j=0,n=1;

do{clrscrn();
	
   printf("Subtraction\n\n\n\n");   
   printf(" j-i: %10d      \n\n",j-i);
   
   j  = rp_I (9000)+999;
   i  = rp_I ( 900)+99;
   
   printf("   j: %10d         \n",j    );
   printf("  -i: %10d       (%d)",i,n++);
   
   nlign(6);   
   stop();

}while(n<=loop);

   clrscrn();
   printf("Subtraction\n\n\n\n");
   printf("  %d - %d = %d     (%d)\n",i,j,j-i,--n); 
   nlign(6);    
   stop();


/* ---------------------------------- */
/* ---------------------------------- */
loop=5;
n=1,i=0;

do{clrscrn();
   
   printf("division\n\n\n\n");
   printf("  %d \n\n",i);
   
   i = rp_I (90)+9;
   j = rp_I (9);
   
   if(n<=loop) printf("  %d / %d  (%d) ",i*j,j,n++);
   else       n++;
   
   nlign(6);        
   stop();

}while(n<=loop);

   clrscrn();
   printf("division            \n\n\n\n");  
   printf("  %d / %d           \n\n",i*j,j);
   printf("  %d         (%d)   \n\n",i,--n);
   nlign(6);    
   stop();


/* ---------------------------------- */
/* ---------------------------------- */
loop=5;
i=1,j=1,n=1;

do{clrscrn();
	
   printf(" r = a %% b   \n\n");             
   printf(" r = %d          (%d) \n\n",(i%j),(n-1));  
   
   i  =   rp_I (90)+9;
   j  =   rp_I ( 7)+2;  
    
   if(n<=loop) printf(" r = %d  %% %d    (%d) ",i,j,n++);
   else       n++;

   nlign(6);  
   stop();

}while(n<=loop);

   clrscrn();
   printf(" r = a %% b            \n\n\n\n");  
   printf(" r = %d  %% %d    (%d) \n\n",i,j,--n); 
   printf(" r = %d                \n\n",(i%j));
   nlign(6);  
   stop();
/* ---------------------------------- */
loop=5;
i=1,j=1,n=1;

do{clrscrn();
	
  printf(" r = (-)a %% b           \n\n"); 	
  
   if((i%j)) printf(" r = %d           (%d)  \n\n",(i%j)+j,(n-1));  
   else      printf(" r = %d           (%d)  \n\n", 0,     (n-1));  
  
   i  = -(rp_I (90)+9);
   j  =   rp_I ( 7)+2 ;
   
   if(n<=loop) printf(" r = %d  %% %d    (%d) ",i,j,n++);
   else       n++;

   nlign(6);  
   stop();

}while(n<=loop);

   clrscrn();
   printf(" r = (-)a %% b          \n\n\n\n");  
   printf(" r = %d  %% %d    (%d) \n\n",i,j,--n); 
   printf(" r = %d                \n\n",(i%j)+j);
   nlign(6);  
   stop();


/* ---------------------------------- */
/* ---------------------------------- */
loop=5;
n=1,i=0;

do{clrscrn();
	
   printf("Multiplication 2\n\n\n\n");
   printf("  %d           \n\n",i*j);
   
   i = rp_I(90)+9;
   j = rp_I(90)+9;
   
   if(n<=loop) printf("  %d * %d  (%d)",i,j,n++);
   else       n++;
   
   nlign(6);   
   stop();

}while(n<=loop);

   clrscrn();
   printf("Multiplication 2\n\n\n\n");
   printf("  %d * %d = %d     (%d)\n",i,j,j*i,--n);    
   nlign(6);    
   stop();
/* ---------------------------------- */
loop=5;
n=1,i=0;

do{clrscrn();
	
   printf("Carre 2\n\n");
   printf("  %d           \n\n",i*j);
   
   i = j =  rp_I(90)+9;
   
   if(n<=loop) printf("  %d * %d  (%d)",i,j,n++);
   else       n++;
   
   nlign(6);   
   stop();

}while(n<=loop);

   clrscrn();
   printf("Carre 2\n\n\n\n");
   printf("  %d * %d = %d     (%d)\n",i,j,j*i,--n);    
   nlign(6);    
   stop();
   
   
/* ---------------------------------- */
/* ---------------------------------- */
loop=5;
i=0,n=1;

do{clrscrn();
	
   printf("Multiplication 3\n\n\n");
   printf("  %d           \n\n",i*j);
   
   i = rp3_I(5);
   j = rp3_I(5);
   
   if(n<=loop) printf("     %4d\n    *%4d  (%d)",i,j,n++);
   else       n++;
   
   nlign(6);  
   stop();

}while(n<=loop);

   clrscrn();
   printf("Multiplication 3\n\n\n\n");
   printf("  %d * %d = %d     (%d)\n",i,j,j*i,--n);    
   nlign(6);    
   stop();
/* ---------------------------------- */
loop=5;
i=0,n=1;

do{clrscrn();
	
   printf("Carre 3\n\n");
   printf("  %d           \n\n",i*j);
   
   i = j = rp3_I(5);
 
   if(n<=loop) printf("     %4d\n    *%4d  (%d)",i,j,n++);
   else       n++;
   
   nlign(6);  
   stop();

}while(n<=loop);

   clrscrn();
   printf("Carre 3\n\n\n\n");
   printf("  %d * %d = %d     (%d)\n",i,j,j*i,--n);    
   nlign(6);    
   stop();


/* ---------------------------------- */
/* ---------------------------------- */
loop=1;
i=0,n=1;

do{clrscrn();
	
   printf("Multiplication 4 \n\n");
   printf("  %d             \n\n",i*j   );
   
   i = rp4_I(2);
   j = rp4_I(2);
   
   if(n<=loop) printf("     %4d\n    *%4d  (%d)",i,j,n++);
   else       n++;
   
   nlign(6);  
   stop();

}while(n<=loop);

   clrscrn();
   printf("Multiplication 4\n\n\n\n");
   printf("  %d * %d = %d     (%d)\n",i,j,j*i,--n);    
   nlign(6);    
   stop();
/* ---------------------------------- */
loop=1;
i=0,n=1;

do{clrscrn();
	
   printf("Carre 4 \n\n");
   printf("  %d    \n\n",i*j);
   
   i =j = rp4_I(2);
 
   if(n<=loop) printf("     %4d\n    *%4d  (%d)",i,j,n++);
   else       n++;
   
   nlign(6);  
   stop();

}while(n<=loop);

   clrscrn();
   printf("Carre 4\n\n\n\n");
   printf("  %d * %d = %d     (%d)\n",i,j,j*i,--n);    
   nlign(6);    
   stop();


/* ---------------------------------- */
/* ---------------------------------- */
loop=1;
i=0,n=1;

do{clrscrn();
	
   printf("Multiplication 5 \n\n");
   printf("  %d             \n\n",i*j   );
   
   i = rp5_I(2);
   j = rp5_I(2);
   
   if(n<=loop) printf("     %4d\n    *%4d  (%d)",i,j,n++);
   else       n++;
   
   nlign(6);  
   stop();

}while(n<=loop);

   clrscrn();
   printf("Multiplication 5\n\n\n\n");
   printf("  %d * %d = %d     (%d)\n",i,j,j*i,--n);    
   nlign(6);    
   stop();
/* ---------------------------------- */
loop=1;
i=0,n=1;

do{clrscrn();
	
   printf("Carre 5 \n\n");
   printf("  %d    \n\n",i*j);
   
   i =j = rp5_I(2);
 
   if(n<=loop) printf("     %4d\n    *%4d  (%d)",i,j,n++);
   else       n++;
   
   nlign(6);  
   stop();

}while(n<=loop);

   clrscrn();
   printf("Carre 5\n\n\n\n");
   printf("  %d * %d = %d     (%d)\n",i,j,j*i,--n);    
   nlign(6);    
   stop();
   
 return 0;
}
/* ---------------------------------- */
/* ---------------------------------- */


C'est un petit utilitaire pour s'entraîner aux calculs (30 minutes).

Cette présentation n'est pas correcte. Le listing est trop long. Il faudrait couper ce fichier en trois ou quatre autres fichiers.