fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void) {
  5. int row, col, **arr, i, j, val;
  6. printf("Enter row and column.\n");
  7. scanf("%d %d", &row, &col);
  8. arr = (int**) malloc(sizeof(int*) * row);
  9. for(i = 0; i < row; ++i) {
  10. arr[i] = (int*) malloc(sizeof(int) * col);
  11. }
  12. printf("Enter the value of array elements\n");
  13.  
  14. for(i = 0; i < row; ++i) {
  15. for(j = 0; j < col ;++j) {
  16. scanf("%d", &val);
  17. arr[i][j] = val * val;
  18. }
  19. }
  20. printf("The result is\n");
  21. for(i = 0; i < row; ++i) {
  22. for(j = 0; j < col ;++j) {
  23. printf("%d ", arr[i][j]);
  24. }
  25. printf("\n");
  26. }
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 9424KB
stdin
3 2
1 2 3 4 5 6 
stdout
Enter row and column.
Enter the value of array elements
The result is
1 4 
9 16 
25 36