Find the maximum value of any number of parameters

Source: Internet
Author: User

Source: Find the maximum of any number of parameters

"C and Pointers" 7th Chapter 4th Programming Questions:

Write a function called Max_list, which checks for any number of integer parameters and returns the maximum value in them. The argument list must end with a negative value, prompting the end of the list.

1 /*2 * * Find the maximum value in any number of integer parameters3 */4 5#include <stdio.h>6 /*7 * * To implement a mutable parameter list, you need to include the Stdarg.h file8 * * va_list, Va_start, Va_arg and Va_end are declared in Stdarg.h9 */Ten#include <stdarg.h> One  A intMax_list (intn, ...); -  - int  the Main () - { -printf"%d", Max_list (Ten, at, the, About, the, the, -, -1) ); - } +  - /* + * * Accept any positive integer to return the maximum value A * * The parameter list must end with a negative value, indicating the end of the list at */ - int  -Max_list (intN, ...) - { - va_list Val; -     intMax =0; in     inti; -     intCurrent ; to      +     /* - * * Ready to access mutable parameters the     */ * Va_start (Val, n); $     Panax Notoginseng     /* - * * Remove values from the mutable list the * * Negative tip list End +     */ A      while(current = Va_arg (Val,int)) >=0 ) the     {     +         if(Max <Current ) -Max =Current ; $     } $      -     /* - * * Complete processing of mutable lists the     */ - Va_end (val);Wuyi      the     returnMax; -}

Find the maximum value of any number of parameters

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.