| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1204 人关注过本帖
标题:f=1!+3!+5!+....+(2n+1)! f=1!+2!+3!+......+n!
只看楼主 加入收藏
YueWuSS
Rank: 2
等 级:论坛游民
帖 子:15
专家分:96
注 册:2011-10-29
收藏
得分:2 
回复 楼主 小桥滴水
//System:Windows 7
//Complier:VS2010
#include <iostream>
using namespace std;

int main(int argc, int *argv[])
{
    int fun1(int);
    for(int i =1;i<10;++i)  //测试fun1 函数
    {
        cout<<fun1(i)<<endl;
    }
    int fun2(int);   //测试fun2 函数
    for(int i = 1;i < 15; i += 2)
    {
        cout<<fun2(i)<<endl;
    }
    //cout.operator<<(cout.tellp());
}

int fun1(int n) //计算1!+2!+3!+...+n!;
{
    if(n<1) return 0;
    int s = n;
    while(--n)
    {
        ++s;
        s *= n;
    }
    return s;
}

int fun2(int n)  //计算1!+3! + 5!+...
{
    if(0 == n%2 || n<1) return 0;
    n--;
    int s = n*(n+1) + 1;

    while(n)
    {
        n -= 2;
        if(!n) break;
        s = s * n*(n+1) + 1;
    }
    return s;
}
2011-10-31 20:59
快速回复:f=1!+3!+5!+....+(2n+1)! f=1!+2!+3!+......+n!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013516 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved