Exercise 3: Finding Index of Smallest Value

Let's test your understanding of templates by finding the index of the smallest value in an array.

Problem Statement

In the code widget below, two functions both called index_of_smallest are declared. One finds the minimum value index of an int type array and the other for double type.

In this exercise, you need to define a Template Class type function index_of_smallest that will generalize the function such that it finds the minimum value index for both int and double type array input values. The function for finding the index of the smallest value in an array takes the following two values:

  • Array of values

  • Size of array

Note: Remove both the int and double type index_of_smallest functions and then write the code for the Template Class type index_of_smallest function there.

Sample input

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy