Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template<class T>
- // Correction of fun1
- double fun1(T* arr, int size) {
- double sum = 0;
- for (int i = 0; i < size; ++i) {
- cin >> arr[i];
- sum += arr[i];
- }
- return sum/size;
- }
- template<class T>
- void fun2(T* arr, int size, T* max, int* maxIndex) {
- *max = arr[0];
- for (int i = 0; i < size; ++i) {
- if (arr[i] > *max) {
- *max = arr[i];
- *maxIndex = i;
- }
- }
- }
- int main()
- {
- int n = 5;
- double a[n];
- double avg = fun1(a, n);
- cout << "Average is " << avg << endl;
- double max = 0;
- int maxIndex = 0;
- fun2(a, n, &max, &maxIndex);
- cout << "The maximum is " << max;
- cout << " with a maximum index of " << maxIndex << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement