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 39 40 41 42 43 44 45 46 47 48
|
#include <stdio.h>
#include <stdlib.h>
unsigned long puissance(unsigned long a,unsigned long b)
{
int res = 1;
while(b>0)
{
res*=a;
b--;
}
return res;
}
int main(void)
{
int end=0;
while(!end)
{
char s[16];
printf("saisissez une entier positif (ou <enter> pour quitter) : ");
fflush (stdout);
fgets(s, sizeof s, stdin);
end = *s=='\n';
if (!end)
{
unsigned long a;
unsigned long b;
unsigned long res;
a = strtoul(s, NULL, 10);
printf("saisissez la puissance (positive) : ");
fflush (stdout);
fgets(s, sizeof s, stdin);
b = strtoul(s, NULL, 10);
res = puissance(a,b);
printf("le resultat est:%lu\n",res);
}
}
return 0;
} |
Partager