1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <stdio.h>
#include <signal.h>
int x,y,nb=0,vrai=0;
void afficheReponse(){
printf("la réponse était %d*%d=%d\n",x,y,x*y);
}
void note(){
printf("vous avez %f/20\n",(float)(vrai/nb)*20);
}
int main(void){
int res;
struct sigaction inc_cpt;
inc_cpt.sa_handler=afficheReponse;
inc_cpt.sa_flags=SA_RESTART;
sigaction(SIGALRM,&inc_cpt,NULL);
signal(SIGINT,note);
for(;;nb++){
x=rand()%10;
y=rand()%10;
alarm(5);
printf("%d*%d:",x,y);
scanf("%d",&res);
if(res==x*y){
printf("bravo\n");
vrai++;
}
else
}
return 0;
} |
Partager