Advertisement
BladeMechanics

matrixFunctions

Feb 22nd, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include "staticmatrix.h"
  4.  
  5. void input(int(*input)[C])
  6. {
  7.     int row, col;
  8.     for (row = 0; row < R; row++)
  9.     {
  10.         for (col = 0; col < C; col++)
  11.         {
  12.             printf("\nEnter value for pos[%d,%d]\n", col, row);
  13.             scanf_s("%d", &input[row][col]);
  14.         }
  15.     }
  16. }
  17.  
  18. //void matrixProduct(int A[][C], int B[][C])
  19. //{
  20. //  int row2 = 0, col2 = 0, psum = 0, product[R][C];
  21. //  for (int row = 0; row < R; row++)
  22. //  {
  23. //      for (int col = 0; col < C; col++)
  24. //      {
  25. //          for (int control = row; control < R; control++)
  26. //              psum += A[control][col2] + B[row2][control];
  27. //
  28. //      }
  29. //  }
  30. //
  31. //
  32. //
  33. //  printf("\nThe product of matrix A and B is: \n");
  34. //  display(product);
  35. //}
  36.  
  37.  
  38.  
  39. void matrixSum(int A[][C], int B[][C])
  40. {
  41.     int row, col, sum[R][C];
  42.     for (row = 0; row < R; row++)
  43.     {
  44.         for (col = 0; col < C; col++)
  45.         {
  46.             sum[row][col] = A[row][col] + B[row][col];
  47.         }
  48.     }
  49.     printf("\nThe sum of matrix A and B is: \n");
  50.     display(sum);
  51. }
  52.  
  53. void displayTranspose(int a[][C])
  54. {
  55.     for (int row = 0; row<R; row++)
  56.     {
  57.         printf("\n");
  58.         for (int column = 0; column<C; column++)
  59.         {
  60.             printf("  %d  ", a[column][row]);
  61.         }
  62.     }
  63. }
  64.  
  65.  
  66. void display(int a[][C])
  67. {
  68.     for(int row=0; row<R; row++)
  69.     {
  70.         printf ("\n");
  71.         for(int column=0; column<C; column++)
  72.         {
  73.         printf ("  %d  ", a[row][column]);
  74.         }
  75.     }
  76. }
  77. float average(int a[][C])
  78. {
  79.     float total=0;
  80.     int count=0;
  81.     for(int row=0; row<R; row++)
  82.     {
  83.         printf ("\n");
  84.         for(int column=0; column<C; column++)
  85.         {
  86.         total+=a[row][column];
  87.         count++;
  88.         }
  89.     }
  90.     return total/count;
  91. }
  92.  
  93. int findlowest(int a[][C])
  94. {
  95.     int lowest=10;
  96.     for(int row=0; row<R; row++)
  97.     {
  98.         for(int column=0; column<C; column++)
  99.         {
  100.         if (a[row][column]<lowest)
  101.             lowest=a[row][column];
  102.         }
  103.     }
  104.     return lowest;
  105. }
  106. int isSquare(int a[][C])
  107. {
  108.     int rowcount=0, columncount=0;
  109.  
  110.     for(int row=0; row<R; row++)
  111.     {
  112.         rowcount++;
  113.     }
  114.  
  115.     for(int column=0; column<C; column++)
  116.     {
  117.         columncount++;
  118.     }
  119.     if (rowcount==columncount)
  120.         return 1;
  121.     else
  122.         return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement