//Drew Boone
//CpSc 1010 S23
//Lab 4
//02/14/2023
//This lab asks the user to input 20 integers for array1 and generates 20 random integers for array2. It then finds the second highest value of each and calculates the inner product.


#include<stdio.h>
#include<stdlib.h>
int main(void)
{
	int array1[20], array2[20];
	int input, i;
		printf("Enter 20 integers: \n");
	for (i=0; i<20; i++){
		fscanf(stdin, "%d", &input);
		array1[i]= input;
	}
	printf("array1:\n");
	for (i=0; i<20; i++)
		printf("%d\n", array1[i]);

	for (i=0; i<20; i++){
		array2[i] = rand() % 50 + 1;
		
	}
	printf("... initializing array2 ...\n");
	printf("array2:\n");
	for (i=0; i<20; i++){ 
		printf("%d\n", array2[i]);
	}
	
	int high_array1 = array1[0];
	int second_array1 = array1[0];
	for (i=0; i<20; i++){
		if (array1[i] > high_array1){
			second_array1 = high_array1;
			high_array1 = array1[i];
		} else if (array1[i] > second_array1 && array1[i] != high_array1){			
			second_array1 = array1[i];
		}
	} printf("\nsecond highest from array1 is: %d\n", second_array1);


	int high_array2 = array2[0];
	int second_array2 = array2[0];
	for (i=0; i<20; i++){
		if (array2[i] > high_array2){
			second_array2 = high_array2;
			high_array2 = array2[i];
		} else if (array2[i] > second_array2 && array2[i] != high_array2){
			second_array2 = array2[i];
		}
	} 
	printf("second highest from array2 is: %d\n", second_array2);

	
	int inner_product = 0;
	for (i = 0; i<20; i++) {
		inner_product += array1[i] * array2[i];
	}
	printf("\ninner product is: %d\n", inner_product);
		
}
