Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab8.c given below. Have to make sure it has the following 6 files. Im so confus

ID: 3811109 • Letter: L

Question

Lab8.c given below. Have to make sure it has the following 6 files. Im so confused on this. Need super help.

/*
Wesley Grant
Lab:01
3/17/2017
Lab 8
user choose 4 different ways of initializing each array. After each initialization,the array should be printed to the user to show it was initialized correctly by calling a printArray funtion.
*/


#include <stdio.h>
void numbers(int array[20])
{
int i;
for(i=0;i<20;i++)
{
array[i]=i+1;
}
}
void evenNumbers(int array[20])
{
int i;
int j=2;
for(i=0;i<20;i++)
{
array[i]=j;
j +=2;
}
}
void oddNumbers(int array[20])
{
int i;
int j=1;
for(i=0;i<20;i++)
{
array[i]=j;
j+=2;
}
}
void fibbonacci(int array[20])
{
int i;
int n1=0;
int n2=1;
array[0]=n1;
array[1]=n2;
for(i=2;i<20;i++)
{
array[i]=n1+n2;
n1=n2;
n2=array[i];
}
}
int main(void)
{
int n=0;
int array1[20],array2[20],array;
int product=0;
int i;
int option=0;
do
{
printf("Choose 1-4 to intialize an array");
printf(" 1.all numbers from 1-20");
printf(" 2.the first 20 even numbers beginning with 2");
printf(" 3.the 20 odd numbers beginning with 1");
printf(" 4.the first 20 fibbonacci numbers, beginning with 0 and 1 ");

scanf("%d",&option);
switch(option)
{
case 1: if(n==0)
numbers(array1);
else
numbers(array2);
break;
case 2: if(n==0)
evenNumbers(array1);
else
evenNumbers(array2);
break;
case 3: if(n==0)
oddNumbers(array1);
else
oddNumbers(array2);
break;
case 4: if(n==0)
fibbonacci(array1);
else
fibbonacci(array2);
break;
}
n++;
if(n==2)
break;
}while(n<=2);
  

for(i=0;i<20;i++)
{
printf("%d ",array1[i]);
}
printf(" ");
for(i=0;i<20;i++)
{
printf("%d ",array2[i]);
}
printf(" ");
for(i=0;i<20;i++)
{
product = product + array1[i]*array2[i];
}
printf("The inner product of the arrays are %d ",product);

return 0;
}

Copy your lab8.c file over to your lab 10 directory. Ifyou did not complete lab8.c,then you'll need to complete that file before working on this lab. Along with your main function, your lab8.c program should consist of the following functions: void initialize (int a J) void all (int a void even t a 1) (in void odd (int a void fib (in a t void print Array (int a 1); int inner Product in a r J, int b 1) t For this lab, you will end up with the following 6 files: 1. lab10.c main will be implemented here the arrays will still be declared here the initialization and print functions are called from here the inner Product function will be called from here, and the result of the inner Product function will be returned back here to the main function which will print the result to the user 2. initialize.c the following functions and their implementations will reside in this module void initialize (int a J) void all (int a void even t a 1) (in void odd (int a void fib int a 1); 3. print.c the print Array function will be in this module 4. inner Product.c the inner Product function will be in this module 5. lab10. h all the needed C library include statements will be in this header file, as well as the #define for the SIZE of the arrays (if you didn't use fdefine for SIZE, then you should change your code to use this preprocessor constant), and also all the function prototypes 6. makefile provided for you on Canvas (download this file to your labl0 directory)

Explanation / Answer

//Header file

//Maximum size is 100
#define MAX 100
//prototype declaration of functions
void numbers(int array[20]);
void evenNumbers(int array[20]);
void oddNumbers(int array[20]);
void fibbonacci(int array[20]);

//Initialize.c file

//Function to initialize an array
void numbers(int array[20])
{
int i;
//Loops till 20
for(i=0;i<20;i++)
{
array[i]=i+1;
}//End of loop
}//End of function

//To generate and store even numbers in array
void evenNumbers(int array[20])
{
int i;
int j=2;
for(i=0;i<20;i++)
{
array[i] = j;
//Adds 2 to previous value of j
j += 2;
}//End of loop
}//End of function

//Function to generate and store odd numbers in array
void oddNumbers(int array[20])
{
int i;
int j=1;
for(i=0;i<20;i++)
{
array[i]=j;
//Adds 2 to previous value of j
j+=2;
}//End of loop
}//End of function

//To generate fibbonacci series and store it in array
void fibbonacci(int array[20])
{
int i;
int n1=0;
int n2=1;
array[0]=n1;
array[1]=n2;
for(i=2;i<20;i++)
{
array[i]=n1+n2;
n1=n2;
n2=array[i];
}//End of loop
}//End of function

//print.c file

#include<stdio.h>
//Displays array contents
void print(int arr[20])
{
int x;
for(x = 0; x < 20; x++)
printf("%6d", arr[x]);
}//End of function

//lab8.c file

#include<stdio.h>
#include"lab10.h"
#include "print.c"
#include"initialize.c"
//Main function
int main(void)
{
int n = 0;
int array1[20],array2[20],array;
int product = 0;
int i;
int option = 0;
//Displays menu
do
{
printf(" Choose 1-4 to intialize an array");
printf(" 1.all numbers from 1-20");
printf(" 2.the first 20 even numbers beginning with 2");
printf(" 3.the 20 odd numbers beginning with 1");
printf(" 4.the first 20 fibbonacci numbers, beginning with 0 and 1 ");
//Accepts user choice
scanf("%d", &option);
switch(option)
{
case 1:
if(n == 0)
numbers(array1);
else
numbers(array2);
break;
case 2:
if(n==0)
evenNumbers(array1);
else
evenNumbers(array2);
break;
case 3:
if(n==0)
oddNumbers(array1);
else
oddNumbers(array2);
break;
case 4:
if(n==0)
fibbonacci(array1);
else
fibbonacci(array2);
break;
}//End of switch
n++;
if(n == 2)
break;
}while(n<=2);

print(array1);
printf(" ");
print(array2);
printf(" ");
for(i=0;i<20;i++)
{
product = product + array1[i]*array2[i];
}
printf("The inner product of the arrays are %d ",product);
return 0;
}//End of main

Sample run1:

Choose 1-4 to intialize an array
1.all numbers from 1-20
2.the first 20 even numbers beginning with 2
3.the 20 odd numbers beginning with 1
4.the first 20 fibbonacci numbers, beginning with 0 and 1
1

Choose 1-4 to intialize an array
1.all numbers from 1-20
2.the first 20 even numbers beginning with 2
3.the 20 odd numbers beginning with 1
4.the first 20 fibbonacci numbers, beginning with 0 and 1
2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
The inner product of the arrays are 5740

Sample run2:

Choose 1-4 to intialize an array
1.all numbers from 1-20
2.the first 20 even numbers beginning with 2
3.the 20 odd numbers beginning with 1
4.the first 20 fibbonacci numbers, beginning with 0 and 1
1

Choose 1-4 to intialize an array
1.all numbers from 1-20
2.the first 20 even numbers beginning with 2
3.the 20 odd numbers beginning with 1
4.the first 20 fibbonacci numbers, beginning with 0 and 1
3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
The inner product of the arrays are 5530

Sample run3:

Choose 1-4 to intialize an array
1.all numbers from 1-20
2.the first 20 even numbers beginning with 2
3.the 20 odd numbers beginning with 1
4.the first 20 fibbonacci numbers, beginning with 0 and 1
1

Choose 1-4 to intialize an array
1.all numbers from 1-20
2.the first 20 even numbers beginning with 2
3.the 20 odd numbers beginning with 1
4.the first 20 fibbonacci numbers, beginning with 0 and 1
4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
The inner product of the arrays are 201210