帮忙编程求前100项整数之和、thankyou、!
编程求前100项整数之和、最好格式安排好、我复制比较方便
2012-03-28 11:15
2012-03-28 12:06
程序代码:template<size_t N> struct foo
{
static const size_t val = foo<N-1>::val + N;
};
template<> struct foo<0>
{
static const size_t val = 0;
};
#include <iostream>
int main()
{
std::cout << foo<100>::val << std::endl;
std::cout << (1+100)*100/2 << std::endl;
return 0;
}
2012-03-28 16:16
2012-03-28 16:19
2012-03-29 10:27
2012-03-31 16:09
2012-04-20 21:46
2012-04-29 06:49
2012-04-29 10:53
2012-05-01 18:45