We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. C
  3. Functions
  4. Variadic functions in C
  5. Discussions

Variadic functions in C

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • ahmedjaved1161
    8 months ago+ 0 comments
    int  sum (int count,...) {
    
        int sum = 0;
        va_list p;
        
        va_start(p, count);
        
        for(int i = 0; i < count; i++){
            sum += va_arg(p, int);
        }
        
        va_end(p);
        
        return sum;
    }
    
    int min(int count,...) {
        
        va_list p;
        va_start(p, count);
        
        int min = va_arg(p, int);
        
        for(int i = 0; i < count - 1; i++){
            int temp = va_arg(p, int);
            
            if(temp < min){
                min = temp;
            }
        }
        
        va_end(p);
        
        return min;
    }
    
    int max(int count,...) {
    
        va_list p;
        va_start(p, count);
        
        int max = va_arg(p, int);
        
        for(int i = 0; i < count - 1; i++){
            int temp = va_arg(p, int);
            
            if(temp > max){
                max = temp;
            }
        }
        
        va_end(p);
        
        return max;
    }
    
    1|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy