Array Processing. In this problem, you have two tasks: To create the header file, arrayOptn.h, and add the function declarations of the following functions listed below. To create the file, arrayOptn.c, which implements the functions in the arrayOptn.h You are already provided with the main() function. Do not edit anything there in the main.c file.
Array Processing.
In this problem, you have two tasks:
- To create the header file, arrayOptn.h, and add the function declarations of the following functions listed below.
- To create the file, arrayOptn.c, which implements the functions in the arrayOptn.h
You are already provided with the main() function. Do not edit anything there in the main.c file.
-
5 - void printElementsInAscending(int arr[], int count)
-
Parameters:
- int arr[] - a reference to the array to be processed
- int count - the number of elements in the array
-
Description:
- Prints all the elements of the passed array in ascending order
- The format of the message is: "Elements: el1 el2 el3 elx" where e1, el2, el3, elx are the current elements of the array.
-
-
6 - void printElementsInDescending(int arr[], int count)
-
Paramters:
- int arr[] - a reference to the array to be processed
- int count - the number of elements in the array
-
Description:
- Prints all the elements of the passed array in descending order
- The format of the message is: "Elements: el1 el2 el3 elx" where e1, el2, el3, elx are the current elements of the array
-
main.c:
#include<stdio.h>
#include "arrayOptn.h"
#define MAX_SIZE 100
int main(void) {
int array[MAX_SIZE];
int count = 0;
int numberOfCommands;
printf("Enter number of commands: ");
scanf("%d", &numberOfCommands);
printf("Enter count of elements: ");
scanf("%d", &count);
printf("\n");
int command;
int elem, k;
for(int c = 1; c <= numberOfCommands; c++) {
printf("COMMAND #: ");
scanf("%d", &command);
switch(command) {
case 1:
createArray(array, count, MAX_SIZE);
printf("\n");
break;
case 2:
printArray(array, count);
printf("\n\n");
break;
case 3:
printf("Enter element: ");
scanf("%d", &elem);
printf("Return Value: %d", locateIndex(array, count, elem));
printf("\n\n");
break;
case 4:
printf("Enter element: ");
scanf("%d", &elem);
printf("Return Value: %d", locateElement(array, count, elem));
printf("\n\n");
break;
case 5:
printElementsInAscending(array, count);
printf("\n\n");
break;
case 6:
printElementsInDescending(array, count);
printf("\n\n");
break;
case 7:
printf("Enter element: ");
scanf("%d", &elem);
printf("Enter position: ");
scanf("%d", &k);
printf("Return Value: %d", insertAtPos(array, &count, elem, k));
printf("\n\n");
break;
case 8:
printf("Enter element: ");
scanf("%d", &elem);
printf("Return Value: %d", insertFront(array, &count, elem));
printf("\n\n");
break;
case 9:
printf("Enter position: ");
scanf("%d", &k);
printf("Return Value: %d", removeAtPos(array, &count, k));
printf("\n\n");
break;
case 10:
printf("Enter element: ");
scanf("%d", &elem);
printf("Return Value: %d", removeElement(array, &count, elem));
printf("\n\n");
break;
case 11:
printf("Return Value: %d", removeFront(array, &count));
printf("\n\n");
}
}
return 0;
}
Step by step
Solved in 2 steps