Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Kata {
- public static int MaxProduct(int[] arr, int size) {
- // sort integers from largest to smallest
- // iterate through the array/list multiplying integers until the counter is equal to size value.
- // return result
- int temp = 0;
- int result = 0;
- for(int a = 0;a < arr.Length;a++)
- {
- for(int b = a+1;b < arr.Length;b++)
- {
- if(arr[a] < arr[b])
- {
- temp = arr[a];
- arr[a] = arr[b];
- arr[b] = temp;
- }
- }
- }
- for(int x = 0;x < size;x++)
- {
- if(result == 0)
- {
- result = arr[x];
- }
- else
- {
- result = result * arr[x];
- }
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement