fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void avrg_allset(double A[3][5])
  6. {
  7. double sumup,average;
  8. int i,j;
  9. for (i=0;i<=2;i++)
  10. {
  11. for (j=0;j<5;j++)
  12. {
  13. sumup+=A[i][j];
  14. }
  15. }
  16. average=sumup/15;
  17. cout <<"The average value for all three sets is: \n"<< average<<endl;
  18.  
  19. }
  20.  
  21. double largest_value(double A[3][5])
  22. {
  23. int i,j;
  24. for(i = 0;i < 3; ++i)
  25. {
  26. for(j=0;j<5;j++)
  27. {
  28. if(A[0][0]<A[i][j])
  29. {
  30. A[0][0]=A[i][j];
  31. }
  32. }
  33. }
  34. return A[0][0];
  35. }
  36.  
  37. void one_set_avrg(double A[3][5])
  38. {
  39. int i=0,j=0;
  40. double sum[3]={0,0,0};
  41. double avrg[3]={0,0,0};
  42. for (i=0;i<3;i++)
  43. {
  44. for (j=0;j<5;j++)
  45. {
  46. sum[i]+= A[i][j];
  47. }
  48. avrg[i]=sum[i]/5;
  49.  
  50. }
  51. cout <<"The average value for first set is: \n"<< avrg[0]<<endl;
  52. cout <<"The average value for second set is: \n"<< avrg[1]<<endl;
  53. cout <<"The average value for third set is: \n"<< avrg[2]<<endl;
  54.  
  55.  
  56. }
  57. int main()
  58. {
  59. double A[3][5];
  60. double B[15];
  61. int j=0,i=0;
  62. double temp;
  63. cout << "Input the numbers for first set \n";
  64. cin >> A[0][0]>>A[0][1]>>A[0][2]>>A[0][3]>> A[0][4];
  65. cout << "Input the numbers for second set \n";
  66. cin >> A[1][0]>>A[1][1]>>A[1][2]>>A[1][3]>> A[1][4];
  67. cout <<"Input the numbers for third set \n";
  68. cin >> A[2][0]>>A[2][1]>>A[2][2]>>A[2][3]>>A[2][4];
  69.  
  70. cout <<"The numbers in ascending order is as below: \n";
  71. for (i=0;i<3;i++)//convert two-dimensional array into one-dimensional array
  72. {
  73. for(j=0;j<5;j++)
  74. {
  75. B[i*5+j]=A[i][j];
  76.  
  77. }
  78.  
  79. }
  80. for (i=0;i<15;i++)//sort 15 values in ascending order
  81. {
  82. if(B[i]>=B[i+1])
  83. {
  84. temp = B[i];
  85. B[i] = B[i+1];
  86. B[i+1] = temp;
  87. }
  88. cout << B[i]<<",";
  89. }
  90.  
  91. one_set_avrg( A );
  92. avrg_allset( A );
  93. cout <<endl;
  94.  
  95. cout <<"Largest number is: \n"<< largest_value( A ) <<endl;
  96.  
  97.  
  98. return 0;
  99.  
  100. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Input the numbers for first set 
Input the numbers for second set 
Input the numbers for third set 
The numbers in ascending order is as below: 
0,0,5.43223e-312,0,0,0,0,0,0,2.35257e-310,2.35257e-310,2.35257e-310,2.35257e-310,2.35257e-310,0,The average value for first set is: 
2.78134e-310
The average value for second set is: 
0
The average value for third set is: 
2.35257e-310
The average value for all three sets is: 
1.7113e-310

Largest number is: 
1.38524e-309