// Vector元素求和.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
string make_plural(size_t ctr, const string &word, const string &ending);
void Get_Vector(vector<double>::iterator begin,vector<double>::iterator end)
{
double sum = 0.0;
while (begin != end)
{
sum += *begin++;
}
cout << sum;
}
char &change_value(string &str, string::size_type ix)
{
return str[ix];
}
int factorial(int val)
{
if (val > 1)
{
return val * factorial(val - 1);
}
else if (val < 0)
{
return -1;
}
else
{
return 1;
}
}
int factorial2(int val)
{
int res = 1;
for (int i = 1; i <= val;++i)
{
res *= i;
}
return res;
}
int sum(int, int);
string make_plural(size_t ctr, const string &word, const string &ending = "s")
{
return (ctr == 1) ? word + ending : word;
}
int _tmain(int argc, _TCHAR* argv[])
{
string b = "go e";
double array[3] = { 2.0, 3.0, 5.0 };
vector<double> ivec(array,array+3);
Get_Vector(ivec.begin(), ivec.end());
cout << b << endl;
change_value(b, 3) = 'E';
cout << b << endl;
int T = factorial(0);
cout << T << endl;
int TT = factorial2(3);
cout << TT << endl;
printf("%d", sum(3, 4));
cout <<make_plural(1,"success","es");
getchar();
return 0;
}
int sum(int a, int b)
{
int sum = 0;
sum = a + b;
return sum;
}