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 Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

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

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

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

9,841 questions

13,453 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 3 days ago by avibootz
edited 2 days ago by avibootz
...