RodneyFrancalim

Matriz identidade

Feb 23rd, 2015
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3.  
  4. int MatrizIdentidade(int nxn)
  5. {
  6.     if(nxn <= 0)
  7.         return printf("Número de linhas (colunas) inválido.");
  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.     MatrizIdentidade(3);
  19.     system("PAUSE");
  20. }
Advertisement
Add Comment
Please, Sign In to add comment