/* ------------------------------------------------------------ */
/* Haagen Williams, 02/17/2023                                 */
/* CpSc 1011 Lab Section 002, Lab 4:                                    */
/* This lab will take an input of 20 integers and output the second highest from array 1 and 2 and the inner product*/
/* ------------------------------------------------------------ */

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

int main(void) {
    // variables
    int array1[20];
    int array2[20];
    int largest1;
    int largest2;
    int secondlargest1;
    int secondlargest2;
    int product;

    // get array1
    printf("Enter 20 integers:\n");
    for (int i = 0; i < 20; i++) {
        scanf("%d", &array1[i]);
    }
    
    // print array1
    printf("\narray1:\n");
    for (int i = 0; i < 20; i++) {
        printf("%d\n", array1[i]);
    }
    
    // assign random to array2
    for (int i = 0; i < 20; i++) {
        array2[i] = rand() % 49 + 1;
    }

    // print array2
    printf("\narray2:\n");
    for (int i = 0; i < 20; i++) {
        printf("%d\n", array2[i]);
    }
    
    largest1 = array1[0];
    largest2 = array2[0];
    for (int i = 0; i < 20; i++) {
        if (array1[i] > largest1) {
            secondlargest1 = largest1;
            largest1 = array1[i];
        }
        if (array2[i] > largest2) {
            secondlargest2 = largest2;
            largest2 = array2[i];
        }
    }
    printf("second highest from array1 is: %d\n", secondlargest1);
    printf("second highest from array2 is: %d\n", secondlargest2);
    
    for (int i = 0; i < 20; i++) {
        product += array1[i] * array2[i];
    }
    printf("inner product is: %d\n", product);
    
    return 0;
}
