Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. double giveMeMaxmum(double theArray[], int size)
  2. {
  3. double max = theArray[0];
  4. for (int i = 1; i < size; i++)
  5. {
  6. if (max <= theArray[i])
  7. {
  8. max = theArray[i];
  9. }//endif
  10. }//endfor
  11. return max;
  12. }//end max
  13.  
  14.  
  15. int main()
  16. {
  17. const int FIVE = 5;
  18. double sampleArray[FIVE];
  19.  
  20. for (int i = 0; i < FIVE; ++i)
  21. {
  22. cout << "Input data for index " << i <<": ";
  23. cin >> sampleArray[i];
  24. }//endfor
  25.  
  26. double sum = 0;
  27.  
  28. double max = sampleArray[0];
  29. double min = sampleArray[0];
  30.  
  31. for (int i = 0; i < FIVE; ++i)
  32. {
  33. cout << "data at index " << i << " = " << sampleArray[i] << endl;
  34. sum = sum + sampleArray[i];
  35.  
  36. if (max <= sampleArray[i])
  37. {
  38. max = sampleArray[i];
  39. }
  40.  
  41. if (min >= sampleArray[i])
  42. {
  43. min = sampleArray[i];
  44. }
  45.  
  46. }//endfor
  47.  
  48. cout << "the sum is " << sum << endl;
  49. cout << "Max is " << max << endl;
  50. cout << "Min is " << min << endl;
  51.  
  52. cout << "the maximum coming from the function is "<< giveMeMaxmum(sampleArray, FIVE) <<endl;
  53.  
  54.  
  55. system("pause");
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement