/* Alex Madsen
   2/14/23
   CpSc 1010, Spring 2023
   Section 4
   Lab #4
   The user will be prompted to input 20 integers for array1 and the rand function will give 20 integers for  array2, then the program will determine the second highest number from each array. The program will then calculate the inner product of the two arrays.
*/ 

#include <stdio.h>
#include <stdlib.h> 

int main () {

	int array1[20];

	int array2[20];

	int i;

	
	printf("Enter 20 integers: \n");

	// user input of 20 integers with loop
	for (i=0; i < 20; i++) {
		scanf("%d", &array1[i]);
	}	
	
	// prints array1
	printf("\n\narray1: \n");
	for (i=0; i < 20; i++) {
		printf("%d\n", array1[i]);
	}	
	
	// assigns random #s to array2
	for (i=0; i < 20; i++) {
		array2[i] = rand() % 50 + 1;
	}
	
	// prints array2
	printf("... initializing array2 ...\n");
	printf("array2: \n");
	for (i=0; i < 20; i++) {
                printf("%d\n", array2[i]);
	}

	// finding 2nd highest # for both arrays	
	int max = array1[0];
	int max2 = 0;
	
	for (i=1; i < 20; i++) {
		if (array1[i] > max)
			max = array1[i];
	} 

	for (i=0; i < 20; i ++) {
		if (max2 < array1[i] && array1[i] < max)
			max2 = array1[i];
	}	

	printf("\nsecond highest from array1 is: %d\n", max2);

	max = array2[0];
	max2 = 0;
	for (i=1; i < 20; i++) {
		if (array2[i] > max)
			max = array2[i];
	} 

	for (i=1; i < 20; i++) {
		if (max2 < array2[i] && array2[i] < max)
			max2 = array2[i];
	}
	
	printf("second highest from array2 is: %d\n", max2);

	
	//calculation of inner product for both arrays
	int ip = 0;
	int temp = 0;
	for (i=0; i < 20; i++) {
		temp = array1[i] * array2[i];
		ip = ip + temp;
	}
	
	printf("\ninner product is: %d\n", ip);


return 0;

}
