need a function of a the C code of this, the instructions of creating the functions for this program are in the images linked to this question. The main program is already written in this question. Please finish the program and create the functions needed to complete this program of mine. Input 1. The number of commands 2. The initial count of elements in the array 3. A series of commands with their corresponding inputs needed Description If the command number is: - 1, the succeeding inputs are the elements of the array. - 2, there are no succeeding inputs - 3, the succeeding input is the element to be searched - 4, the succeeding input is the element to be searched - 5, there are no succeeding inputs - 6, there are no succeeding inputs - 7, the succeeding inputs are the element to be inserted and the index where the element will be inserted - 8, the succeeding input is the element to be inserted - 9, the succeeding input is the index to be removed - 10, the succeeding input is the element to be removed - 11, there are no succeeding inputs
I need a function of a the C code of this, the instructions of creating the functions for this program are in the images linked to this question. The main program is already written in this question.
Please finish the program and create the functions needed to complete this program of mine.
Input
1. The number of commands
2. The initial count of elements in the array
3. A series of commands with their corresponding inputs needed
Description
If the command number is:
- 1, the succeeding inputs are the elements of the array.
- 2, there are no succeeding inputs
- 3, the succeeding input is the element to be searched
- 4, the succeeding input is the element to be searched
- 5, there are no succeeding inputs
- 6, there are no succeeding inputs
- 7, the succeeding inputs are the element to be inserted and the index where the element will be inserted
- 8, the succeeding input is the element to be inserted
- 9, the succeeding input is the index to be removed
- 10, the succeeding input is the element to be removed
- 11, there are no succeeding inputs
#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;
}
The output should be:
Output
Step by step
Solved in 4 steps with 3 images