#include <stdio.h> #define MAX 100 int findMinIndex(int data[], int low, int hig
ID: 3679664 • Letter: #
Question
#include <stdio.h> #define MAX 100 int findMinIndex(int data[], int low, int high); int main() { int i, loop, n, queries, data[MAX]; // Read in the schedule data. FILE* ifp = fopen("schedule.in", "r"); fscanf(ifp, "%d", &n); for (i=0; i<n; i++) fscanf(ifp, "%d", &data[i]); // Process each query. fscanf(ifp, "%d", &queries); for (loop=0; loop<queries; loop++) { int low, high; fscanf(ifp, "%d%d", &low, &high); printf("%d ", findMinIndex(data, low, high)); } return 0; } // Pre-condition: low <= high and are both valid indexes to data. // Post-condition: Returns the lowest index in [low, high] storing // the minimum of array[low]…array[high]. int findMinIndex(int data[], int low, int high) { // Fill this in. return 0; }
Explanation / Answer
int findMinIndex(int data[],int low,int high)
{
//Pre-Condition
if(data[low]<=data[high])
{
printf("both are valid index");
}
else
return data[low];
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.