Chinaunix首页 | 论坛 | 博客
  • 博客访问: 198758
  • 博文数量: 124
  • 博客积分: 7051
  • 博客等级: 少将
  • 技术积分: 1425
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-20 13:21
文章分类

全部博文(124)

文章存档

2008年(124)

我的朋友

分类: C/C++

2008-05-02 09:01:32

   

/*提示:本文内容未全部经过程序测试和经典书籍论证,作者不保证所有内容均完全正确,请正确参考,Copyright @ Shine*/

函数//以下程序都是在vc++6.0中实现,请参考

1.

#include "stdafx.h"

#include

#include

using namespace std;

 

int hermite(int n, int x)//may be error,I only copy it from book logically

{

    if(n <= 0)

       return 1;

    else if(n == 1)

       return (2*x);

    else

       return(2*x*hermite(n-1,x) - 2 * (n-1) * hermite(n-2,x));

}

 

int main(int argc, char *argv[])

{

    printf("The return value of hermite function is %d.\n",hermite(5,2));

 

    system("PAUSE");

    return EXIT_SUCCESS;

}

2.//程序的灵魂在于算法,实现在于编程能力,仅此而已。

#include "stdafx.h"

#include

#include

using namespace std;

 

int gcd(int m, int n)

{

    if((n <= 0) || (m <= 0))

       return 0;

    else if((m % n) == 0)

       return n;

    else

       return gcd(n,m % n);

 

}

 

int main(int argc, char *argv[])

{

    printf("The return value of hermite function is %d.\n",gcd(14,35));

 

    system("PAUSE");

    return EXIT_SUCCESS;

}

3.//常用

#include "stdafx.h"

#include

#include

using namespace std;

 

int asc2int(const char *string)//2(two),常常用来表示to,表示某种转换

{

    int i = 0;

    long value = 0;

    while(*(string + i) != '\0')

    {

       if((*(string + i) >= '0') && (*(string + i)) <= '9')

           value = (value * 10) + (*(string + i) - '0');

       else

           return 0;

       i++;

    }

    return value;

}

 

int main(int argc, char *argv[])

{

    int acs_value = asc2int("11001");

    printf("The return value of \"11001\" is %d.\n",acs_value);

 

    system("PAUSE");

    return EXIT_SUCCESS;

}

4.//stdarg和可变参数的详细信息可以baidu得到

#include "stdafx.h"

#include

#include

#include

using namespace std;

 

int max_list(int x1,...)

{

    int max,temp;

    va_list args;

 

    va_start(args,x1);

    temp = max = x1;

    while (temp > 0)

    {

        max = (max > temp) ? max : temp;

        temp = va_arg(args, int);

    }

    va_end(args);

    return max;

}

 

int main(int argc, char *argv[])

{

    printf("The return value of max_list function is %d.\n",max_list(4,5,6,5,9,45,645,-1));

 

    system("PAUSE");

    return EXIT_SUCCESS;

}

阅读(1323) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~