# 函数模板--求n个数的和

#include <iostream>
using namespace std;
/*
补充缺少代码
*/
int main()
{
double result;
unsigned char c1,c2,c3,c4;
cin>>c1>>c2>>c3>>c4;
result = sum<unsigned char>(c1,c2,c3,c4);
cout<<int(result)<<endl;

int i1,i2,i3,i4;
cin>>i1>>i2>>i3>>i4;
result = sum<int>(i1,i2,i3,i4);
cout<<result<<endl;

double d1,d2,d3,d4;
cin>>d1>>d2>>d3>>d4;
result = sum<double>(d1,d2,d3,d4);
cout<<result<<endl;

return 0;
}

``````abcd
1 2 3 4
1.1 2.2 3.3 4.4``````

``````138
10
11``````

``````#include<stdio.h>
#include<string.h>
int main()
{
int i,b[4],aa=0,bb=0;
float c[4],cc=0.0;
char a[5];
for(i=0;i<4;i++)
{
scanf("%c",&a[i]);
aa+=a[i]-64;
}
for(i=0;i<4;i++)
{
scanf("%d",&b[i]);
bb+=b[i];
}
for(i=0;i<4;i++)
{
scanf("%f",&c[i]);
cc+=c[i];
}
printf("%d\n%d\n%g\n",aa,bb,cc);
return 0;
}

``````

``````
#include <iostream>
using namespace std;
template <class T>
T sum(T a,T b,T c,T d)
{
T sum;
sum=a+b+c+d;
return sum;
}

int main()
{
double result;
unsigned char c1,c2,c3,c4;
cin>>c1>>c2>>c3>>c4;
result = sum<unsigned char>(c1,c2,c3,c4);
cout<<int(result)<<endl;

int i1,i2,i3,i4;
cin>>i1>>i2>>i3>>i4;
result = sum<int>(i1,i2,i3,i4);
cout<<result<<endl;

double d1,d2,d3,d4;
cin>>d1>>d2>>d3>>d4;
result = sum<double>(d1,d2,d3,d4);
cout<<result<<endl;

return 0;
}
``````