fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7. int m[n][n];
  8. for(int i=0;i<n;i++)
  9. {
  10. m[i][i]=1;
  11. }
  12. for(int i=0;i<n;i++)
  13. {
  14. for(int y=0;y<n;y++)
  15. {
  16. if(m[i][y]!=1)
  17. {
  18. m[i][y]=0;
  19. }
  20. }
  21. }
  22. for(int i=0;i<n;i++)
  23. {
  24. for(int y=0;y<n;y++)
  25. {
  26. cout<<m[i][y]<<" ";
  27. }
  28. cout<<"\n";
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0s 3416KB
stdin
3
stdout
1 0 0 
0 1 0 
0 0 1