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

write this c program. Create an array of 10 ints called myArray. Give the array

ID: 3601994 • Letter: W

Question

write this c program.
Create an array of 10 ints called myArray. Give the array contents an initial value of 0 in the variable declaration. Create a loop to prompt the user and get revised values (using getNum) for all of the array elements, pressing ENTER after each of the 10 items. Within the loop, keep track of which element has the lowest value. After the loop is done, display the minimum element's index and value. Do not create any other functions besides getNum. You can assume that the user will always enter valid input.
Change the top to create and call (from main) two functions:
1. changeArray prompts the user and gets values (using getNum) for all of the array elements, pressing ENTER after each of the array elements. Take the array and the number of elements as parameters (failing to do this may result in a failing mark in the Mini-Assignment). This replaces getting the user values in main.
2. minArray that takes the array and number of elements as parameters and returns the minimum element's index (not value). Do not do any output in this function. When you display the final output in main, display both the index and the value, similar to top.
GetNum function
#pragma warning(disable: 4996)
int getNum(void)
{
/* the array is 121 bytes in size; we'll see in a later lecture how we can improve this code */
char record[121] = {0}; /* record stores the string */
int number = 0;
    /* NOTE to student: indent and brace this function consistent with your others */
    /* use fgets() to get a string from the keyboard */
    fgets(record, 121, stdin);
    /* extract the number from the string; sscanf() returns a number
     * corresponding with the number of items it found in the string */
    if( sscanf(record, "%d", &number) != 1 )
    {
        /* if the user did not enter a number recognizable by
         * the system, set number to -1 */
        number = -1;
    }
    return number;
}

Explanation / Answer

Note: Here index value is between 0-9 for 10 elements in array. So output of index will be the index of array if you want it to be from 1-10 just add 1 to index variable.

#include<stdio.h>
int getNum(void);
void changeArray(int [],int);
int minArray(int [],int);
int main() {

int option;
int array[10] = {0};
int min, index;

changeArray(array,10);
min = minArray(array,10);
for(int i=0;i<10;i++){
if(array[i]==min)
{
index = i;
break;
}
}
printf("Minimum value is: %d",min);
printf("Index is: %d",index);
return 0;
}

int getNum(void)
{
char record[121] = {0};
int number = 0;
fgets(record, 121, stdin);
if( sscanf(record, "%d", &number) != 1 )
{
number = -1;
}
return number;
}

void changeArray(int array[], int numElements){
  
for(int i=0; i<numElements; i++){
printf("Enter an integer: ");
array[i] = getNum();
}
return;
}

int minArray(int array[], int numElements){
int min = array[0];
for(int i=1; i<numElements; i++)
{
if (array[i] < min)
min = array[i];
}
return min;
}