Advertisement
RodneyFrancalim

Matriz identidade

Feb 23rd, 2015
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3.  
  4. int MatrizIdentidade(int nxn)
  5. {
  6.     if(nxn <= 0)
  7.         return printf("Numero de linhas (colunas) invalido.\n\n\n");
  8.  
  9.     for(int i = 1; i <= nxn; ++i)
  10.         for(int j = 1; j <= nxn; ++j)
  11.             printf("%d%s", i == j, j == nxn ? ("\n") : (""));
  12.  
  13.     return 1;
  14. }
  15.  
  16. main()
  17. {
  18.     int
  19.         npn = 1;
  20.     ;
  21.    
  22.     while(npn > 0)
  23.     {
  24.         printf("Digite o numero de linhas (colunas) da matriz (use 0 para fechar o programa): ");
  25.         scanf("%d", &npn);
  26.         MatrizIdentidade(npn);
  27.         system("PAUSE");
  28.         system("CLS");
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement