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

Write a C program, in the main function, you need to create an integer array wit

ID: 3759165 • Letter: W

Question

Write a C program, in the main function, you need to create an integer array with 10 elements in it. Use a for loop to read 10 integers from the user and store the values to the array (in the order of input). For example (in the screen shot below) the element with index 0 stores 23, the element with index 1 stores value of 55, the element with index 2 stores the value of 87 and so on.

Once the array is initialized, call a function to get the index number of the largest value in the array. Like the example in the screen shot, the largest number is 98, so the return value of the function should be 5. This function should take the array you created in the main function as a parameter, the number of valid elements in the array, and return the index of the maximum value in the array. The array should not be changed after the function is called. Write the precondition and postcondition for the function.

Explanation / Answer

#include <stdio.h>
int max_index(int a[], int n);
int main()
{
int a[10],i,j,ind;
for(i=0;i<10;i++)
{
printf("enter the %d element ",i+1);
scanf("%d",&a[i]);
}
ind = max_index(a,10);
printf("Index of the largest value = %d ",ind);
}
int max_index(int a[], int n)
{
int max = a[0];//assign first as max
int i,res = 0;// asiign 0 to result
for(i=0;i<n;i++)
{
if(a[i]>max)
{
max= a[i];//update max
res = i;//update reult
}
}
return res;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote