Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
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


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

Liquid Web Cloud VPS Hosting

10,903 questions

14,810 answers

573 users

How to find a pair with maximum product from int array in C

1 Answer

0 votes
#include <stdio.h>

void max_product_from_int_array(int arr[], int len, int *item1, int *item2) { 
    *item1 = arr[0], *item2 = arr[1]; 
  
    for (int i = 0; i < len; i++) 
      for (int j = i + 1; j < len; j++) 
         if (arr[i] * arr[j] > *item1 * *item2) 
            *item1 = arr[i], *item2 = arr[j]; 
} 
  
int main() 
{ 
    int arr[] = {3, 9, 1, 3, 7, 0, 8, 4}; 
    int len = sizeof(arr)/sizeof(arr[0]); 
    int item1 = 0, item2 = 0;
    
    max_product_from_int_array(arr, len, &item1, &item2);
    
    printf("%2i%2i", item1, item2);
    
    return 0; 
} 


/*
run:

 9 8

*/

 




answered Apr 15 by avibootz
edited Apr 15 by avibootz
...