Advertisement
Guest User

Untitled

a guest
May 28th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define MAX 10
  4.  
  5. int main()
  6. {
  7. int dimension, i, j, sum;
  8. typedef int TwoDArray[MAX][MAX];
  9. TwoDArray *array;
  10.  
  11. printf("Enter the dimension of the array: ");
  12. scanf("%d", &dimension);
  13.  
  14. array = malloc(sizeof(int) * (dimension * 2));
  15.  
  16. for (i = sum = 0; i < dimension; i++)
  17. for (j = 0; j < dimension; j++)
  18. {
  19. scanf("%d", &(*array)[i][j]);
  20. sum += (*array)[i][j];
  21. }
  22.  
  23. for (printf("The array:\n\n"), i = 0; i < dimension; i++, printf("\n"))
  24. for (j = 0; j < dimension; j++)
  25. printf("%d ", (*array)[i][j]);
  26.  
  27. printf("\nSum of all elements: %d", sum);
  28.  
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement