Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main () {
  5. const unsigned int n = 5;
  6. unsigned int matrix[n][n];
  7.  
  8. //*************************************
  9.  
  10. unsigned int zahl=0;
  11. unsigned int zeile=0;
  12. unsigned int spalte=-1;
  13. unsigned int w=0;
  14.  
  15. while(zahl<n*n){
  16. for(unsigned int i=0;i<n-w;i++){
  17. spalte ++;
  18. zahl++;
  19. matrix[zeile][spalte]=zahl;
  20. }
  21. w++;
  22. for(unsigned int j=0;j<n-w;j++){
  23. zeile++;
  24. zahl++;
  25. matrix[zeile][spalte]=zahl;
  26. }
  27. for(unsigned int k=0;k<n-w;k++){
  28. spalte--;
  29. zahl++;
  30. matrix[zeile][spalte]=zahl;
  31. }
  32. w++;
  33. for(unsigned int l=0;l<n-w;l++){
  34. zeile--;
  35. zahl++;
  36. matrix[zeile][spalte]=zahl;
  37. }
  38. }
  39.  
  40.  
  41.  
  42. //*************************************
  43.  
  44. for (unsigned int r = 0; r < n; ++r){
  45. for (unsigned int c = 0; c < n; ++c){
  46. if (matrix [r][c] < 10){
  47. cout << ' ';
  48. }
  49. cout << matrix[r][c] << ' ';
  50. }
  51. cout << endl;
  52. }
  53.  
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement