#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;
}
四年一闰,百年不闰,四百年再闰(即:判断条件能被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;
}
#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;
}
#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;
}
#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;
}
本文出自 “追寻内心的声音” 博客,请务必保留此出处http://ljy789.blog.51cto.com/10697684/1828626