Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- template<class T>
- int comp(T min[],int size)
- {
- int minn=min[0],index=0;
- for (int i=0; i < size; i++)
- {
- if (min[i] < min[index])
- {
- minn = min[i];
- index = i;
- }
- }
- return minn;
- }
- int main()
- {
- int all[] = { 20, 17, 39, 18, 22, 46 };
- double another[] = { 7.65, 3.4, 2.11, 1.5, 4.33 };
- cout << "all裡最小值是:" << comp<int>(all, sizeof(all)/sizeof(int)) << endl;
- cout << "another裡最小值是:" << comp<double>(another, sizeof(another)/sizeof(double)) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement