Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. int pick, i, a, b, j;
  4. int q[100];
  5. float tmp;
  6. int u;
  7. int p=0;
  8. int m[50][50];
  9. int z[100];
  10. int n[5][5] = {
  11. {1, 2, 3, 4, 5},
  12. {5, 6, 7, 8, 9},
  13. {9, 10, 11, 12, 13},
  14. {13, 14, 15, 16, 17},
  15. {17, 18, 19, 20, 21}
  16. };
  17. int
  18. main ()
  19. {
  20. printf ("Press 1 if you want to enter your own matrix..\n");
  21. printf ("Press 2 if you want to use a predetermined matrix..\n");
  22. scanf ("%d", &pick);
  23. for(i=0;i<100;i++)
  24. {
  25. z[i]=0;
  26. }
  27. if (pick == 1)
  28. {
  29. printf ("How many rows do you want in your matrix?\n");
  30. scanf ("%d\n", &a);
  31. printf ("How many columns do you want in your matrix?\n");
  32. scanf ("%d\n", &b);
  33. printf ("Enter the elements of your matrix row by row..\n");
  34. for(i=0;i<a;i++)
  35. {
  36. for(j=0;j<b;j++)
  37. {
  38. printf("Enter the [%d][%d] element ",i+1,j+1);
  39. scanf("%d\n",&m[i][j]);
  40. }
  41. }
  42. printf ("Your matrix is..\n");
  43. for (i = 0; i < a; i++)
  44. {
  45. for (j = 0; j < b; j++)
  46. {
  47. printf ("[%d]", m[i][j]);
  48. }
  49. printf ("\n");
  50. }
  51. //////////////////////// Above this im having problems printing the correct matrix. I enter 1,2,3 and it prints 3,1,2
  52. printf("Press 1 for the average.. Press 2 for the standard deviation ");
  53. scanf ("%d", &pick);
  54. if (pick==1)
  55. {
  56. printf("Press 1 to choose the average per row.. Press 2 for per column ");
  57. scanf ("%d", &pick);
  58. if (pick == 1)
  59. {
  60. printf ("This matrix has %d rows, which do you want to print? ",a);
  61. scanf ("%d", &pick);
  62. tmp = 0;
  63. for (i = 0; i < a; i++)
  64. {
  65. tmp = tmp + m[pick - 1][i];
  66. }
  67. tmp = tmp * 0.2;
  68. printf ("%d is the average of row %d", tmp, pick);
  69. }
  70. else if (pick==2)
  71. {
  72. printf("This matrix has 5 columns, which do you want to print? ");
  73. scanf ("%d", &pick);
  74. tmp = 0;
  75. for (i = 0; i < b; i++)
  76. {
  77. tmp = tmp + m[i][pick - 1];
  78. }
  79. tmp = tmp * 0.2;
  80. printf ("%d is the average of column %d", tmp, pick);
  81. }
  82. }
  83. else if (pick == 2)
  84. {
  85. printf("Press 1 for the standard devation per row.. Press 2 per column ");
  86. scanf ("%d",&pick);
  87. if (pick == 1)
  88. {
  89. printf ("This matrix has %d rows, which do you want to print? ",a);
  90. scanf ("%d", &pick);
  91. u = 0;
  92. for (i = 0; i < a; i++)
  93. {
  94. u = u + m[pick - 1][i];
  95. }
  96. u = u*0.2;
  97. for(i=0;i<a;i++)
  98. {
  99. z[i]=m[pick-1][i]-u;
  100. }
  101. for(i=0;i<a;i++)
  102. {
  103. z[i]=z[i]*z[i];
  104. p=p+z[i];
  105. }
  106. printf("The standard deviation of the %d row is sqrt(%d/%d)",pick,p,a-1);
  107. }
  108. else if (pick == 2)
  109. {
  110. printf ("This matrix has %d columns, which do you want to print? ",b);
  111. scanf ("%d", &pick);
  112. u = 0;
  113. for (i = 0; i < b; i++)
  114. {
  115. u = u + m[i][pick-1];
  116. }
  117. u = u*0.2;
  118. for(i=0;i<b;i++)
  119. {
  120. z[i]=m[i][pick-1]-u;
  121. }
  122. for(i=0;i<b;i++)
  123. {
  124. z[i]=z[i]*z[i];
  125. p=p+z[i];
  126. }
  127. printf("The standard deviation of the %d column is sqrt(%d/%d)",pick,p,b-1);
  128. }
  129. }
  130. }
  131.  
  132. ///////////////////////////////// Ends the personal matrix code
  133. else if (pick==2)
  134. {
  135. printf ("The predetermined matrix is..\n");
  136. for (i = 0; i < 5; i++)
  137. {
  138. for (j = 0; j < 5; j++)
  139. {
  140. printf ("[%d]", n[i][j]);
  141. }
  142. printf ("\n");
  143. }
  144.  
  145.  
  146.  
  147. printf("Press 1 for the average.. Press 2 for the standard deviation ");
  148. scanf ("%d", &pick);
  149. if (pick==1)
  150. {
  151. printf("Press 1 to choose the average per row.. Press 2 for per column ");
  152. scanf ("%d", &pick);
  153. if (pick == 1)
  154. {
  155. printf ("This matrix has 5 rows, which do you want to print? ");
  156. scanf ("%d", &pick);
  157. tmp = 0;
  158. for (i = 0; i < 5; i++)
  159. {
  160. tmp = tmp + n[pick - 1][i];
  161. }
  162. tmp = tmp * 0.2;
  163. printf ("%d is the average of row %d", tmp, pick);
  164. }
  165. else if (pick==2)
  166. {
  167. printf("This matrix has 5 columns, which do you want to print? ");
  168. scanf ("%d", &pick);
  169. tmp = 0;
  170. for (i = 0; i < 5; i++)
  171. {
  172. tmp = tmp + n[i][pick - 1];
  173. }
  174. tmp = tmp * 0.2;
  175. printf ("%d is the average of column %d", tmp, pick);
  176. }
  177. }
  178. else if (pick == 2)
  179. {
  180. printf("Press 1 for the standard devation per row.. Press 2 per column ");
  181. scanf ("%d",&pick);
  182. if (pick == 1)
  183. {
  184. printf ("This matrix has 5 rows, which do you want to print? ");
  185. scanf ("%d", &pick);
  186. u = 0;
  187. for (i = 0; i < 5; i++)
  188. {
  189. u = u + n[pick - 1][i];
  190. }
  191. u = u*0.2;
  192. for(i=0;i<5;i++)
  193. {
  194. z[i]=n[pick-1][i]-u;
  195. }
  196. for(i=0;i<5;i++)
  197. {
  198. z[i]=z[i]*z[i];
  199. p=p+z[i];
  200. }
  201. printf("The standard deviation of the %d row is sqrt(%d/4)",pick,p);
  202. }
  203. else if (pick == 2)
  204. {
  205. printf ("This matrix has 5 columns, which do you want to print? ");
  206. scanf ("%d", &pick);
  207. u = 0;
  208. for (i = 0; i < 5; i++)
  209. {
  210. u = u + n[i][pick-1];
  211. }
  212. u = u*0.2;
  213. for(i=0;i<5;i++)
  214. {
  215. z[i]=n[i][pick-1]-u;
  216. }
  217. for(i=0;i<5;i++)
  218. {
  219. z[i]=z[i]*z[i];
  220. p=p+z[i];
  221. }
  222. printf("The standard deviation of the %d column is sqrt(%d/4)",pick,p);
  223. }
  224. }
  225. }
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement