/*  lab 4 - arrays  
	 Spring 2023, CpSc 101    	
*/

//  easier to use redirection from a file to get the values  

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// #include <time.h>   // let's not seed it so we can check their values


int main( void ) {

	int input, i, size = 20, array1[size], array2[size]; 
	int highest1, highest2, second_highest1, second_highest2; 
	int inner_product = 0;

	// ---------------  array1 ---------------
	// initialize
	printf( "Enter 20 integers:  \n\n" );
	for( i = 0; i < size; i++ ) {
		scanf( "%d", &input );
		array1[i] = input;
	}
	// print out array1
	printf("\narray1: \n");
	for( i = 0; i < size; i++ ) 
		printf("%d\n", array1[i]); 

	// ---------------  array2 ---------------
	// srand(time(0));  
	// initialize
	// printf( "... initializing array2 ...  \n" );
	for( i = 0; i < size; i++ ) {
		array2[i] = rand() % 50 + 1;
	}
	// print out array2
	printf("\narray2: \n");
	for( i = 0; i < size; i++ ) 
		printf("%d\n", array2[i]);

	// ---------  second highest value ---------
	// find highest value first
	highest1 = array1[0];
	highest2 = array2[0];
	for( i = 1; i < size; i++ ) {
		if(array1[i] > highest1)
			highest1 = array1[i];
		if(array2[i] > highest2)
			highest2 = array2[i];
	}
	// then find second highest
	second_highest1 = array1[0];
	second_highest2 = array2[0];
	for( i = 1; i < size; i++ ) {
		if( (array1[i] > second_highest1) && (array1[i] < highest1) ) 
			second_highest1 = array1[i];
		if( (array2[i] > second_highest2) && (array2[i] < highest2) ) 
			second_highest2 = array2[i];
	}
	printf("second highest from array1 is: %d\n", second_highest1);
	printf("second highest from array2 is: %d\n\n", second_highest2);

	// ------------  inner product ------------
	for( i = 0; i < size; i++ ) 
		inner_product = inner_product + (array1[i] * array2[i]);
	printf("inner product is: %d\n\n", inner_product);

	return 0;
}
