fork download
  1. //
  2. // main.c
  3. // hello word
  4. //
  5. // Created by 陳稚鎧 on 2017/2/7.
  6. // Copyright © 2017年 陳稚鎧. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <time.h>
  12. void max_fun(const int vx[5][3], int vy[1][3]){
  13. int i,j;
  14. for (i=0; i<3; i++)
  15. vy[0][i]=vx[0][i];
  16.  
  17. for (i=0; i<3; i++) {
  18. for (j=0; j<5; j++) {
  19. if (vx[j][i]>vy[1][i])
  20. vy[1][i]=vx[j][i];
  21.  
  22. }
  23. }
  24.  
  25. }
  26. void average_fun(const int vx[5][3], double vy[1][3]){
  27. int i,j;
  28.  
  29. for (i=0; i<3; i++)
  30. vy[1][i]=0;
  31.  
  32. for (i=0; i<3; i++) {
  33. for (j=0; j<5; j++) {
  34. vy[1][i] += vx[j][i];
  35. }
  36. }
  37. for (i=0; i<3; i++) {
  38. vy[1][i] = vy[1][i]/5;
  39. }
  40.  
  41. }
  42.  
  43.  
  44. int main(void) {
  45. // unsigned seed;
  46. // seed = (unsigned)time(NULL); // 取得時間序列
  47. // srand(seed); // 以時間序列當亂數種子
  48. int v[5][3],max[1][3];
  49. double ave[1][3];
  50. int i,j;
  51. for (i=0; i<5; i++) {
  52. for (j=0; j<3; j++) {
  53. v[i][j]=(rand() % 100) +1;
  54. }
  55. }
  56.  
  57. for (i=0; i<5; i++) {
  58. for (j=0; j<3; j++) {
  59. printf("v[%d][%d]=%d\t",i+1,j+1,v[i][j]);
  60. }
  61. putchar('\n');
  62. }
  63. putchar('\n');
  64.  
  65.  
  66. average_fun(v,ave);
  67.  
  68. for (j=0; j<3; j++) {
  69. printf("ave[1][%d]=%f\t",j+1,ave[1][j]);
  70. }
  71. putchar('\n');
  72.  
  73. max_fun(v, max);
  74.  
  75. for (j=0; j<3; j++) {
  76. printf("max[1][%d]=%d\t",j+1,max[1][j]);
  77. }
  78. putchar('\n');
  79.  
  80. for (i=0; i<5; i++) {
  81. for (j=0; j<3; j++) {
  82. printf("v[%d][%d]=%d\t",i+1,j+1,v[i][j]);
  83. }
  84. putchar('\n');
  85. }
  86. putchar('\n');
  87.  
  88.  
  89. return 0;
  90. }
  91.  
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
v[1][1]=84	v[1][2]=87	v[1][3]=78	
v[2][1]=16	v[2][2]=94	v[2][3]=36	
v[3][1]=87	v[3][2]=93	v[3][3]=50	
v[4][1]=22	v[4][2]=63	v[4][3]=28	
v[5][1]=91	v[5][2]=60	v[5][3]=64	

ave[1][1]=40.000000	ave[1][2]=43.200000	ave[1][3]=216150870.800000	
max[1][1]=1432700252	max[1][2]=60	max[1][3]=64	
v[1][1]=1078198272	v[1][2]=-1717986918	v[1][3]=1078303129	
v[2][1]=-1382442598	v[2][2]=1101644902	v[2][3]=36	
v[3][1]=87	v[3][2]=93	v[3][3]=50	
v[4][1]=22	v[4][2]=63	v[4][3]=28	
v[5][1]=91	v[5][2]=60	v[5][3]=64