Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main () {
- const unsigned int n = 5;
- unsigned int matrix[n][n];
- //*************************************
- unsigned int zahl=0;
- unsigned int zeile=0;
- unsigned int spalte=-1;
- unsigned int w=0;
- while(zahl<n*n){
- for(unsigned int i=0;i<n-w;i++){
- spalte ++;
- zahl++;
- matrix[zeile][spalte]=zahl;
- }
- w++;
- for(unsigned int j=0;j<n-w;j++){
- zeile++;
- zahl++;
- matrix[zeile][spalte]=zahl;
- }
- for(unsigned int k=0;k<n-w;k++){
- spalte--;
- zahl++;
- matrix[zeile][spalte]=zahl;
- }
- w++;
- for(unsigned int l=0;l<n-w;l++){
- zeile--;
- zahl++;
- matrix[zeile][spalte]=zahl;
- }
- }
- //*************************************
- for (unsigned int r = 0; r < n; ++r){
- for (unsigned int c = 0; c < n; ++c){
- if (matrix [r][c] < 10){
- cout << ' ';
- }
- cout << matrix[r][c] << ' ';
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement