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 37 38
| #include <stdio.h>
#include <string.h>
int saisie()
{
char buf[1024];
char other[1024];
int n;
char *c;
while (1)
{
fputs("Entrer un entier positif : ", stdout);
fflush(stdout);
fgets(buf, 1024, stdin);
if (c=strchr(buf, '\n')) *c='\0';
if (sscanf(buf, "%d", &n) == 0 || (sprintf(other, "%d", n), strcmp(buf, other) != 0))
{
printf("La valeur [%s] n'est pas un nombre entier - Recommencez\n", buf);
continue;
}
if (n < 0)
{
printf("Le nombre [%d] est négatif - Recommencez\n", n);
continue;
}
return n;
}
}
int main ()
{
int entier, i;
entier=saisie();
for(i=1;i<=10;i++)
printf("%d x %d = %d\n",entier,i,entier*i);
return 0;
} |
Partager