Adding Array

#include <iostream>
using namespace std;
template <class T>
  T sum(T n1, T n2, T n3, T n4, T n5)
{
  return n1+n2+n3+n4+n5;
}
int main() {
int a,b,c,d,e;
  float f,g,h,i,j;
  cin>>a>>b>>c>>d>>e>>f>>g>>h>>i>>j;
  cout<<sum(a,b,c,d,e)<<endl;
  cout<<sum(f,g,h,i,j);
return 0;
}

6 comments:

  1. Replies
    1. 3rd line- remove the space between template and

      Delete
  2. #include
    using namespace std;
    template
    T sum(T a,T b,T c,T d,T e)
    {
    float h;
    h=(a+b+c+d+e);
    cout<>a>>b>>c>>d>>e;
    cin>>q>>w>>r>>t>>y;
    sum(a,b,c,d,e);
    sum(q,w,r,t,y);
    }

    ReplyDelete
  3. #include
    using namespace std;
    template
    T sum(T n1, T n2, T n3, T n4, T n5)
    {
    return n1+n2+n3+n4+n5;
    }
    int main() {
    int a,b,c,d,e;
    float f,g,h,i,j;
    cin>>a>>b>>c>>d>>e>>f>>g>>h>>i>>j;
    cout<<sum(a,b,c,d,e)<<endl;
    cout<<sum(f,g,h,i,j);
    return 0;
    }

    ReplyDelete
  4. #include
    using namespace std;
    template
    T sum(T n1, T n2, T n3, T n4, T n5)
    {
    return n1+n2+n3+n4+n5;
    }
    int main() {
    int a,b,c,d,e;
    float f,g,h,i,j;
    cin>>a>>b>>c>>d>>e>>f>>g>>h>>i>>j;
    cout<<sum(a,b,c,d,e)<<endl;
    cout<<sum(f,g,h,i,j);
    return 0;
    }

    ReplyDelete
  5. replce "typename" with "class" in the 3rd line

    ReplyDelete