C基礎(11——15)

wKioL1eQ42HDeQ1vAABzSkpuu54488.png

#include <stdio.h>
#include <stdlib.h>

void test()
{
                 int i=0;
                 int j=0;
                 int k=0;
                 int count=0;

                 for(i=1;i<5;i++)
                {
                                 for(j=1;j<5;j++)
                                {
                                                 for(k=1;k<5;k++)
                                                {
                                                                 if((i!=j)&&(j!=k)&&(i!=k))
                                                                {
                                                                                count++;
                                                                                printf( "%d%d%d ",i,j,k);
                                                                }
                                                }
                                }
                }
                printf( "\nthe total=%d\n",count);
}
int main()
{
                test();
                system( "pause");
                 return 0;
}

wKiom1eQ46Gi_MHAAAASnJ6g-4E484.png


wKioL1eQ48-D--bFAAAvGKk3HwI159.png

四年一閏,百年不閏,四百年再閏(即:判斷條件能被4整除但不能被100整除,或者能被400整除(year%4==0&&year%100!=0)||(year%400==0))

#include <stdio.h>
#include <stdlib.h>

void test()
{
                 int i=0;
                 int count=0;

                 for(i=1;i<2000;i++)
                {
                                 if((i%4==0&&i%100!=0)||(i%400==0))
                                {
                                                count++;
                                                printf( "%d ",i);
                                }
                }
                printf( "\nthe total leap year before 2000 year=%d\n" ,count);
}
int main()
{
                test();
                system( "pause");
                 return 0;
}

wKioL1eQ5AKRAoTVAACYNjCVLm8849.png


wKiom1eQ5CvxTgZcAAA-JMaaCcM797.png

#include <stdio.h>
#include <stdlib.h>

void test()
{
                 float i=2;
                 float j=1;
                 float sum=0;
                 float tmp=2;
                 int count=0;  //用於計數,前多少項

                 while(count<20)
                {
                                sum+=i/j;
                                count++;

                                tmp=i;
                                i=i+j;
                                j=tmp;
                }

                printf( "sum=%f\n",sum);
}
int main()
{
                test();
                system( "pause");
                 return 0;
}

wKiom1eQ54zzqeq3AAAHK3XQRi8941.png


wKioL1eQ5G_iTDg6AABPRmXAIas833.png

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void test()
{
                 int a=0;
                 int n=0;
                 int b=0;
                 int s=0;
                 int i=0;

                printf( "依次輸入a,n的值\n" );
                scanf( "%d",&a);
                scanf( "%d",&n);

                b=a;

                 for(i=1;i<=n;i++)
                {
                                s+=a;
                                a=b*pow(10.0,i)+a;
                }

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

wKioL1eQ5Jzy5Zh8AAAMl6m0jFE631.png


wKiom1eQ5LPxROa6AABTPYowaDk721.png

#include <stdio.h>
#include <stdlib.h>

void test()
{
                 double h=100;
                 double s=0;

                 for(int i=1;i<=10;i++)
                {
                                s+=h*2;
                                h=h/2;
                }
                s=s-100;  //第一次多加了一個100

                printf( "第10次落地時,共經過%f米,第10次反彈%f米高\n" ,s,h);
}
int main()
{
                test();
                system( "pause");
                 return 0;
}

wKiom1eQ5NGgTW7MAAAPiyOF6X8283.png


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章