fork download
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3.  
  4. #define asize 20
  5.  
  6. int main()
  7. {
  8. int** a = new int*[asize];
  9. unsigned long sum = 0;
  10. for(int i = 0; i < asize; i++)
  11. {
  12. a[i] = new int[asize];
  13. bool isNull = false;
  14. for(int j = 0; j < asize; j++)
  15. {
  16. a[i][j] = rand()%3;
  17. if(isNull) sum += a[i][j];
  18. if(i == j && a[i][j] == 0)
  19. {
  20. for(int k = 0; k < j; k++)
  21. sum += a[i][k];
  22. isNull = true;
  23. }
  24. printf("%2d",a[i][j]);
  25. }
  26. printf("%c",'\n');
  27. }
  28. printf("sum = %u",sum);
  29. for(int i = 0; i < asize; i++)
  30. delete [] a[i];
  31. delete [] a;
  32. return 0;
  33. }
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
 1 1 0 1 2 1 1 0 0 1 2 1 2 1 2 1 0 0 1 1
 2 2 0 0 2 2 2 1 1 1 2 0 0 0 2 0 1 1 1 1
 0 0 0 2 2 1 2 2 2 0 2 1 1 2 2 0 2 2 1 1
 0 0 2 0 2 2 1 0 1 2 0 0 0 0 2 0 2 2 0 2
 1 0 0 2 2 0 0 2 2 1 0 0 2 0 1 1 1 0 0 2
 0 1 2 1 2 0 2 2 0 0 1 2 1 2 2 1 0 2 1 2
 1 0 0 1 0 2 0 2 0 1 0 1 2 0 0 2 1 2 2 2
 1 0 2 2 0 2 0 0 1 2 1 0 0 2 2 1 2 0 1 2
 2 1 2 2 1 2 1 1 2 1 0 1 2 2 0 0 2 1 0 1
 1 2 2 1 2 2 0 1 2 1 2 1 0 1 2 2 0 0 0 0
 2 1 1 1 2 2 2 1 1 1 0 0 0 0 2 0 2 0 0 2
 2 2 1 2 1 0 2 2 2 1 0 2 0 2 1 0 0 1 2 2
 2 0 2 0 1 2 1 1 2 1 0 1 1 0 1 2 0 2 1 0
 0 2 2 1 0 2 2 0 0 2 0 0 2 2 0 1 2 2 0 2
 0 1 1 2 1 0 1 2 2 1 0 0 1 0 2 1 2 2 2 0
 1 2 0 0 0 1 0 0 1 0 2 2 1 1 0 0 2 2 0 2
 0 0 1 0 1 1 2 1 0 2 1 1 2 2 2 0 2 2 0 1
 0 1 1 2 2 1 0 2 1 0 2 2 1 0 2 1 1 2 2 2
 2 2 0 2 2 0 0 1 0 1 2 1 2 2 0 2 0 1 1 1
 2 1 1 1 2 1 2 1 1 2 0 0 1 1 1 2 2 1 0 0
sum = 166