fork download
  1. #include <iostream>
  2.  
  3. int main(){
  4. int x=5;
  5. int y=5;
  6. int matrix[x][y];
  7. for (int i = 0; i<x; i++) {
  8. for (int j =0; j<y; j++){ // wollte nur sichergehen dass kein Ergebnis durch unbestimmte Speicherplätze gefälscht wird
  9. matrix[i][j]=0;
  10. }
  11. }
  12. //unterer Teil
  13. int i=x*x;
  14. int cntx,cnty;
  15. cntx=x;
  16. cnty=x;
  17. for(int min=x-1;min>=0;min--){
  18. cnty=min;
  19. cntx=x;
  20. while(cntx>=min){
  21. matrix[cntx][cnty]=i;
  22. i--;
  23. cntx--;
  24. cnty++;
  25. }
  26. }
  27.  
  28. //Ausgabe
  29. for (int i = 0; i <x; i++) {
  30. for (int j =0; j<y; j++){
  31. std::cout<<matrix[i][j]<<"\t";
  32. }
  33. std::cout<<"\n";
  34. }
  35. }
  36.  
  37.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
0	0	0	0	0	
6	0	0	0	7	
12	0	0	8	13	
17	0	9	14	18	
21	10	15	19	22