Sommaire


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

a08_fun.c
'
/* ---------------------------------- */
/*  Save as :   a08_fun.c             */
/* ---------------------------------- */
#include    "x_ahfile.h"
/* ---------------------------------- */
#define      LOOP         5
/* ---------------------------------- */
int main(void)
{
time_t t;

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

  srand(time(&t));
  
  
do{clrscrn();
	
   printf("Addition\n\n\n\n");   
   printf(" i+j: %10d      \n\n",j+i);
   
   j  = rndp_I (9000)+999;
   i  = rndp_I (9000)+999;
   
   printf("   j: %10d         \n",j    );
   printf("  +i: %10d       (%d)",i,n++);nlign(6);

}while(stop_w());  

clrscrn();

   printf("Addition\n\n\n\n");   
   printf(" i+j: %10d      (%d)\n\n",j+i,--n);

nlign(9);   
getchar();


stop();
i=0,j=0,n=1;

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

}while(stop_w());  

clrscrn();

   printf("Soustraction\n\n\n\n");   
   printf(" j-i: %10d      (%d)\n\n",j-i,--n);

nlign(9);   
getchar();


stop();
n=1,i=0;

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

}while(n<=loop);



n=1,i=0;

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

}while(n<=loop);



i=0,n=1;

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

}while(n<=loop);



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  =   rndp_I (90)+9;
   j  =   rndp_I ( 7)+2;  
    
   if(n<loop) printf(" r = %d  %% %d    (%d) ",i,j,n++);
   else       n++;

   nlign(6);  
   stop();

}while(n<=loop);



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  = -(rndp_I (90)+9);
   j  =   rndp_I ( 7)+2 ;
   
   if(n<loop) printf(" r = %d  %% %d    (%d) ",i,j,n++);
   else       n++;

   nlign(6);  
   stop();

}while(n<=loop);



n=1,i=0;

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

}while(n<=loop);



i=0,n=1;

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

}while(n<=loop);



loop=LOOP-4+1;
i=0,n=1;

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

}while(n<=loop);



loop=LOOP+1;
i=0,n=1;

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

}while(n<=loop);


 return 0;
}


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

De petites corrections ont été effectuées par rapport aux exemples précédents.

Pour passer d'une opération à la suivante vous devez appuyer sur la touche "return", sauf pour sortir des boucles de l'addition et de la soustraction, ou dans ce cas vous appuyez sur deux touches "x" et "return". Pour conserver le bon fonctionnement du programme il faut neutraliser l'une des deux touches. C'est ce que font les "getchar()" dans ce listing. Ce type de bug apparaîtra régulièrement dans nos travaux.

Cet article est issu de Wikibooks. Le texte est sous licence Creative Commons - Attribution - Partage dans les Mêmes. Des conditions supplémentaires peuvent s'appliquer aux fichiers multimédias.