fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. int tab[10][10];
  9.  
  10. srand(time(NULL));
  11.  
  12. for (int i=0;i<10;i++)
  13. {
  14. for (int j=0;j<10;j++)
  15. {
  16. tab[i][j]=rand() % 19 - 9;
  17. }
  18.  
  19. }
  20.  
  21.  
  22. for (int i=0;i<10;i++)
  23. {
  24. for (int j=0;j<10;j++)
  25. {
  26. cout << tab[i][j] << " ";
  27. }
  28. cout << endl;
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. /* for (int i=0;i<10;i++)
  40. {
  41. for (int j=0;j<10;j++)
  42. {
  43. tab[i][j]=(i+1)*(j+1);
  44. cout << tab[i][j] << " ";
  45. }
  46. cout << endl;
  47. }
  48. */
  49. int suma=0;
  50. for (int i=0;i<10;i++)
  51. {
  52. for (int j=0;j<10;j++)
  53. {
  54. if (i==j)
  55. suma+=tab[i][j];
  56. }
  57. }
  58. cout << "Suma po przekatnej: " << suma << endl;
  59.  
  60. return 0;
  61. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
-1 6 -3 -3 5 -4 -9 4 3 -5 
1 6 -8 8 -7 4 -6 2 3 -9 
2 7 -3 1 -2 3 -8 -5 -8 -8 
1 0 7 5 7 0 -9 4 -9 0 
8 1 -4 7 -4 -1 1 -3 7 -9 
-3 -4 7 0 7 -8 9 5 -4 -8 
6 3 -2 3 -5 -8 9 -4 5 9 
5 1 -3 -8 -2 3 -3 5 6 -6 
5 -7 -1 2 0 -7 0 -1 7 2 
-3 3 -8 2 -6 -3 3 -7 2 -4 
Suma po przekatnej: 12