Showing posts with label minimum in array using templates. Show all posts
Showing posts with label minimum in array using templates. Show all posts

Wednesday, May 11, 2022

template func to find minimum in an array

 #include<iostream>

using namespace std;
template<class T>
T mini(T arr[],T size){
    T max=arr[0];
    for(int i=0;i<size;i++){
        if (arr[i]<max)
        {
            max=arr[i];
           
        }
       
    }
    return max;

}

int main(){
    int arr[]={1,2,3,4,1,100,0};
int min=mini<int>(arr,7);//we can use size using size of arr and size of first element division
cout<<min;
    return 0;
}

HackCache ’26: A 48-Hour Online Hackathon Open to Every Student

  Hackathons are often associated with computer science students, experienced developers, and teams that already know exactly what they are...

Popular Posts