Created
August 21, 2013 13:54
-
-
Save ahoulgrave/6294738 to your computer and use it in GitHub Desktop.
Exponentes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> | |
#include <iostream> | |
using namespace std; | |
int potencia(int base, int exp); | |
int main(int argc, char *argv[]) | |
{ | |
int vect[10][12] = {{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}}; | |
for (int j = 0; j < 12; j++) { | |
for (int k = 0; k < 10; k++) { | |
vect[j][k] = potencia(vect[j][0],k+1); | |
} | |
} | |
//Imprimo | |
for (int m = 0; m < 12; m++) { | |
for (int n = 0; n < 10; n++) { | |
printf(" %d ", vect[m][n]); | |
} | |
printf("\n"); | |
} | |
printf("\n\n%d",potencia(2,3)); | |
system("PAUSE"); | |
return EXIT_SUCCESS; | |
} | |
int potencia(int base, int exp) { | |
if (base == 1) { | |
return 1; | |
} | |
if (exp == 0) { | |
return 1; | |
} | |
int r = 1; | |
for (int i = 0; i < exp; i++) { | |
r = r * base; | |
} | |
return r; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment