Sdut Object-Oriented Programming machine Exercise 1 (function overloading)

Source: Internet
Author: User
Tags float max

Sdut Object-Oriented Programming machine Exercise 1 (function overloading)

Object-Oriented Programming machine Exercise 1 (function overloading) Time Limit: 1000 MS Memory limit: 65536 K The topic description uses array and function overload to calculate the maximum number of five numbers (considering integers, single precision, and long integers respectively ). Enter five int integers, five float integers, and five long integers. The output outputs the maximum values of five int integers, the maximum values of five float integers, and the maximum values of five long integers. Sample Input
11 22 666 44 5511.11 22.22 33.33 888.88 55.551234567 222222 333333 444444 555555
Sample output
666888.881234567


# Include
 
  
Using namespace std; // evaluate the maximum number of five integers int max (int a []) {int I; int m = 0; for (I = 0; I <5; I ++) {if (a [I]> m) m = a [I];} return m ;} // evaluate the maximum number of five floating point numbers float max (float a []) {int I; float m = 0.0; for (I = 0; I <5; I ++) {if (a [I]> m) m = a [I];} return m ;}// obtain the maximum long max (long a []) from five long integers. {int I; long m = 0; for (I = 0; I <5; I ++) {if (a [I]> m) m = a [I];} return m;} // main function int main () {int j; int x [5]; float y [5]; long z [5]; // input for (j = 0; j <5; j ++) cin> x [j]; for (j = 0; j <5; j ++) cin> y [j]; for (j = 0; j <5; j ++) cin> z [j]; // output int e; e = max (x); cout <e <endl; float f; f = max (y); cout <f <endl; long g; g = max (z); cout <g <endl; return 0 ;}
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.