Advertisement
Guest User

ejer18

a guest
Nov 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. void validar(int *);
  6. void cargarMatriz(int);
  7. unsigned long potencia(int, int);
  8.  
  9. int main(){
  10.     int m;
  11.     cout<<"Ingrese orden de la matriz: ";
  12.     cin>>m;
  13.     validar(&m);
  14.     cargarMatriz(m);
  15. }
  16.  
  17. void validar(int *M){
  18.     while(*M > 10){
  19.         cout<<"Orden no valido, ingrese un numero menor o igual a 10: ";
  20.         cin>>*M;
  21.     }
  22. }
  23.  
  24. void cargarMatriz(int m){
  25.     int numero = 1,f,c, mat[m][m];
  26.     for(f = 0; f<m; f++){
  27.         for(c = 0; c<m; c++){
  28.             mat[f][c] = potencia(numero, numero); //EN UN PUNTO IMPRIME BASURA PORQUE EL NUMERO YA ES MUY GRANDE
  29.             numero++;
  30.         }
  31.     }
  32.     for(f = 0; f<m; f++){
  33.         for(c = 0; c<m; c++){
  34.             cout<<mat[f][c]<<"\t";
  35.         }
  36.         cout<<"\n";
  37.     }
  38. }
  39.  
  40. unsigned long potencia(int base, int exponente){
  41.     if(exponente == 0){
  42.         return 1;
  43.     }else{
  44.         return base * potencia(base, exponente-1); //LLAMADA RECURSIVA
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement