C和指针第七章的两个题

来源:互联网 发布:网络电视怎么调节亮度 编辑:程序博客网 时间:2024/06/04 23:28
#include <stdio.h>#include <stdlib.h>int asctoint(char * str);int main(){    char a[7];    int t;    printf("输入字符 \n");    gets(a);    t = asctoint(a);    printf("转换后的值%d\n", t);    //printf("Hello world!\n");    return 0;}int asctoint(char * str){    int value = 0;    while( (*str) > '0' && (*str) < '9')    {        value *=10;        value += (*str) - '0';        str++;    }    if(*str != '\0')        value = 0;    return value;}
#include <stdio.h>#include <stdlib.h>#include <math.h>/*厄密多项式计算*/int HM( int n, int x);int main(){    int jj;    jj=HM( 3, 2 );    printf("值是%d!\n", jj);    return 0;}int HM( int n, int x){    int u;    if( n<=0)    {        u = 1;    }    else if( n == 1 )    {        u = 2*x;    }    else    {        u = (2*x*HM( n-1, x) - 2*(n-1)*HM( n-2, x));    }        return u;}
原创粉丝点击