C++mid102_3

 avatar
user_3763047219
c_cpp
a year ago
473 B
0
Indexable
Never
#include <iostream>
using namespace std;

template <typename T>
T sum(T *listt, int n){
    //cout<<listt<<endl;
    T sum =0;
    //cout<<sum<<endl;
    for(int i=0;i<n;i++){
        //cout<<&listt[i]<<endl;;
        sum +=listt[i];
    }
    return sum;
}

int main(){
    int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    double b[10] = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10};

    cout<< sum(a,10) <<endl;
    cout<< sum(b,10)<<endl;
}