matMul.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (C) 2020, 2019, 2018, 2017 Girish M
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. * MA 02110-1301, USA.
  17. *
  18. */
  19. #include <stdio.h>
  20. #include <malloc.h>
  21. int main(void)
  22. {
  23. unsigned int m, n, i, j, k=1;
  24. int* a;
  25. printf("\nEnter the size of matrix:\n");
  26. printf("\nNo. of rows:\n");
  27. scanf("%u", &m);
  28. printf("\nNo. of cols:\n");
  29. scanf("%u", &n);
  30. a = (int*) malloc(sizeof(int)*m*n);
  31. if(NULL != a)
  32. {
  33. for(i=0; i<m; i++)
  34. {
  35. for(j=0; j<n; j++)
  36. {
  37. printf("\nEnter element a[%d][%d]: \n", i+1, j+1);
  38. printf("\nloc: %d\n", i+j+k);
  39. scanf("%d", &a[i+j+k]);
  40. }
  41. k=k+n-1;
  42. }
  43. printf("\nEntered array:\n");
  44. k=1;
  45. for(i=0; i<m; i++)
  46. {
  47. for(j=0; j<n; j++)
  48. {
  49. printf("%d ", a[i+j+k]);
  50. }
  51. printf("\n");
  52. k=k+n-1;
  53. }
  54. free(a);
  55. }
  56. return 0;
  57. }