training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

intpow.c (595B)


      1 /* Esercizio 5.16 */
      2 
      3 #include <stdio.h>
      4 
      5 int integerPower(int, int);
      6 
      7 int main()
      8 {
      9    int b, e;
     10 
     11    printf("Insert base: ");
     12    scanf("%d", &b);
     13    while(b != EOF) {
     14       printf("Insert exponent: ");
     15       scanf("%d", &e);
     16 
     17       printf("\n%d^%d = %d\n", b, e, integerPower(b, e));
     18 
     19       printf("\nInsert base: ");
     20       scanf("%d", &b);
     21    }
     22 
     23    return 0;
     24 } /* E0F main */
     25 
     26 /* Return value of base^exponent */
     27 int integerPower(int base, int exponent)
     28 {
     29    int i, x = base;
     30 
     31    for(i = 1; i < exponent; i++) {
     32       x *= base;
     33    } /* end for (i) */
     34 
     35    return x;
     36 } /* eof integerPower() */
     37