fork download
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <random>
  4. using namespace std;
  5. int main() {
  6. random_device rd;mt19937_64 gen(rd());
  7. uniform_int_distribution<long long> random(1, 1e9);
  8. cout << " Enter the size of array : " << "\n";
  9. int sz;cin >> sz;
  10. long long a[sz][sz];
  11. for (int i = 0;i < sz;i++) {
  12. for (int j = 0;j < sz;j++) {
  13. a[i][j] = random(gen);
  14. cout << a[i][j] << " ";
  15. }
  16. cout << "\n";
  17. }
  18. long long sum = 0,mn = a[0][0],mx = a[0][0];
  19. for (int i = 0;i < sz;i++) {
  20. for (int j = 0;j < sz;j++) {
  21. sum += a[i][j];
  22. // if (mx < a[i][j]) mx = a[i][j];
  23. // if (mn > a[i][j]) mn = a[i][j];
  24. mn = min(mn,a[i][j]);
  25. mx = max(mx,a[i][j]);
  26. }
  27. }
  28. long double avg = (long double) sum / (sz * sz);
  29. long long main_diag = 0, sec_diag = 0;
  30. for (int i = 0; i < sz; i++) {
  31. main_diag += a[i][i];
  32. sec_diag += a[i][sz - i - 1];
  33. }
  34. cout << "Max of array : " << mx << "\n";
  35. cout << "Min of array : " << mn << "\n";
  36. cout << "Average of array : " << fixed << setprecision(10) << avg << "\n";
  37. cout << "Sum of array : " << sum << "\n";
  38. cout << "Sum of Main diagonal : " << main_diag << "\n";
  39. cout << "Sum of Secondary diagonal : " << sec_diag << "\n";
  40. return 0;
  41. }
Success #stdin #stdout 0s 5320KB
stdin
5
stdout
 Enter the size of array : 
755285075 330384191 316655087 425803874 126529280 
488754627 935539716 597000413 231269624 646754476 
673131524 547115101 613530237 782214947 599916887 
316283705 801357947 259627850 653709416 911628711 
839178175 702539519 411301921 137802762 765527405 
Max of array : 935539716
Min of array : 126529280
Average of array : 554753698.8000000000
Sum of array : 13868842470
Sum of Main diagonal : 3723591849
Sum of Secondary diagonal : 2611865263