C基础(26——30)-创新互联

C基础(26——30)

巢湖网站制作公司哪家好,找成都创新互联!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设公司等网站项目制作,到程序开发,运营维护。成都创新互联成立与2013年到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联
如果n越大,则递归计算比较慢
//#include 
//#include 
//
//int FibNoRecursion(int n)  //斐波那契非递归
//{
//             int a=0;
//             int b=1;
//             int c=a+b;
//
//             if(n==0)
//                             return 0;
//             if(n==1)
//                             return b;
//             if(n==2)
//                             return a+b;
//             for(int i=3;i<=n;i++)
//             {
//                             a=b;
//                             b=c;
//                             c=a+b;
//             }
//             return c;
//}
//void test()
//{
//             int n=0;
//             printf("Please input n: ");
//             scanf("%d",&n);
//             int ret=FibNoRecursion(n);
//             printf("Fibonacci(%d) = %d\n",n,ret);
//}
//int main()
//{
//             test();
//             system("pause");
//             return 0;
//}


//数组实现
#include 
#include 

int FibNoRecursion(int n)  //斐波那契非递归
{
                 int fib_arr[100]={0};    //数组元素全部初始化为0
                fib_arr[0]=1;
                fib_arr[1]=1;
                 int count=0;

                 while(count

结果:

C基础(26——30)

C基础(26——30)

#include 
#include 

void test()
{
                 char* str="abcdefghi123" ;
                 int count=0;

                 while(*str)
                {
                                count++;
                                str++;
                }

                printf( "%d\n",count);
}
int main()
{
                test();
                system( "pause");
                 return 0;
}

结果:

C基础(26——30)

C基础(26——30)

//不用临时变量,即可以用递归来求

#include 
#include 

int Strlen(char * str)
{
                 if(*str =='\0')
                                 return 0;
                 if(*str )
                {
                                 str++;
                                 return Strlen(str )+1;
                }
}
void test()
{
                 char* str="0abc123def" ;
                 int ret=Strlen(str);

                printf( "strlen=%d\n",ret);
}
int main()
{
                test();
                system( "pause");
                 return 0;
}

结果:

C基础(26——30)

C基础(26——30)

#include 
#include 
#define N 8
void test()
{
                 int arr[N ]={23,88,12,8,37,99,25,0};

                 for(int i=0;iarr[j])
                                                {
                                                                 int tmp=arr[i];
                                                                arr[i]=arr[j];
                                                                arr[j]=tmp;
                                                }
                                }
                }
                 //输出
                 for(int m=0;m

结果:

C基础(26——30)

C基础(26——30)

C基础(26——30)

#include 
#include 

void test()
{
                 int a=15;
                 int count=0;

                 while(a)
                {
                                 if(a & 1)  //按位与
                                                count++;

                                a=a>>1;
                }

                printf( "%d\n",count);
}
int main()
{
                test();
                system( "pause");
                 return 0;
}

结果:

C基础(26——30)

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站题目:C基础(26——30)-创新互联
本文来源:http://myzitong.com/article/desgos.html