Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Web Hosting

Bonsai Boy of New York Bonsai Trees and Accessories

BlueHost Web Hosting

Liquid Web iThemes WordPress Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


getResponse autofunnels

Liquid Web Cloud VPS Hosting

11,144 questions

15,208 answers

573 users

How to find max in struct array using C

1 Answer

0 votes
#include <stdio.h> 
#include <limits.h> 
 
struct Test { 
    float book_price; 
    int book_tax; 
}; 

int max(int mx, int tmp) {
    if (mx > tmp)
        return mx;
    return tmp;
}

int find_max(struct Test arr[], int len) { 
    int mx = INT_MIN; 
     
    for (int i = 0; i < len; i++) { 
        int tmp = arr[i].book_price + arr[i].book_tax; 
        mx = max(mx, tmp); 
    } 
    return mx; 
} 
   
int main() 
{ 
    struct Test arr[] = { 
        { 4, 6 }, 
        { 1, 7 }, 
        { 11, 5 }, 
        { 8, 6 }, 
        { 2, 3 }, 
        { 7, 5 } 
    }; 
     
    int result = find_max(arr, sizeof arr / sizeof arr[0]); 
     
    printf("%i", result); 
     
    return 0; 
} 
 
 
 
/*
run:
 
16
 
*/

 




answered May 6 by avibootz
...