Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. #include <stdio.h>
  2. int pick,i,a,b,j;
  3. int q[100];
  4. double tmp;
  5. double m[50][50];
  6. double z[100];
  7. int n[5][5]=
  8. {
  9. {1,2,3,4,5},
  10. {5,6,7,8,9},
  11. {9,10,11,12,13},
  12. {13,14,15,16,17},
  13. {17,18,19,20,21}
  14. };
  15. int main ()
  16. {
  17. printf("Press 1 if you want to enter your own matrix..\n");
  18. printf("Press 2 if you want to use a predetermined matrix..\n");
  19. scanf("%d",&pick);
  20. if(pick==1)
  21. {
  22. printf("How many rows do you want in your matrix? ");
  23. scanf("%d\n",&a);
  24. printf("How many columns do you want in your matrix? ");
  25. scanf("%d\n",&b);
  26. printf("Enter the elements of your matrix row by row..");
  27. for(i=0;i<a;i++)
  28. {
  29. for(j=0;j<b;j++)
  30. {
  31. printf("Enter element [%d][%d] ",i,j);
  32. scanf("%d",m[i][j]);
  33. }
  34. printf("\n");
  35. }
  36.  
  37.  
  38. for(i=0;i<a;i++)
  39. {
  40. for(j=0;j<b;j++)
  41. {
  42. printf("%d",m[i][j]);
  43. }
  44. printf("\n");
  45. }
  46. }
  47. else if(pick==2)
  48. {
  49. printf("The predetermined matrix is..\n");
  50. for(i=0;i<5;i++)
  51. {
  52. for(j=0;j<5;j++)
  53. {
  54. printf("[%d]",n[i][j]);
  55. }
  56. printf("\n");
  57. }
  58. printf("Press 1 for the average.. Press 2 for the standard deviation ");
  59. scanf("%d",&pick);
  60. if(pick==1)
  61. {
  62. printf("Press 1 to choose the average per row.. Press 2 for per column ");
  63. scanf("%d",&pick);
  64. if(pick==1)
  65. {
  66. printf("This matrix has 5 rows, which do you want to print? ");
  67. scanf("%d",&pick);
  68. tmp=0;
  69. for(i=0;i<5;i++)
  70. {
  71. tmp=tmp+n[pick-1][i];
  72. }
  73. tmp=tmp*0.2;
  74. printf("%d is the average of row %d",tmp,pick);
  75. }
  76. else if(pick==2)
  77. {
  78. printf("This matrix has 5 columns, which do you want to print? ");
  79. scanf("%d",&pick);
  80. tmp=0;
  81. for(i=0;i<5;i++)
  82. {
  83. tmp=tmp+n[i][pick-1];
  84. }
  85. tmp=tmp*0.2;
  86. printf("%d is the average of column %d",tmp,pick);
  87. }
  88. }
  89. else if(pick==2)
  90. printf("Press 1 for the standard devation per row.. Press 2 per column ");
  91. scanf("%d",pick);
  92. if(pick==1)
  93. {
  94. printf("This matrix has 5 rows, which do you want to print? ");
  95. scanf("%d",&pick);
  96. tmp=0;
  97. for(i=0;i<5;i++)
  98. {
  99. tmp=tmp+n[pick-1][i];
  100. z[i]=n[pick-1][i];
  101. }
  102. tmp=tmp*0.2;
  103. for(i=0;i<5;i++)
  104. {
  105. z[i]=z[i]-tmp;
  106. q[i]=z[i]*z[i];
  107. }
  108. tmp=0;
  109. for(i=0;i<5;i++)
  110. {
  111. tmp=tmp+q[i];
  112. }
  113. tmp=pow(tmp,0.5);
  114. printf("The standard deviation of the %d row is %d",pick,tmp);
  115. }
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement