小さいコードは注意深く3対の親子のプログラミングを含みます
4094 ワード
#include"wz.h"
#define n 5
#define N 5
//1
struct pb{int *p;struct{int x, y;}s;struct pb *next;};
void neicunduiqi() { struct pb w; printf("
size of struct pb%2d
",sizeof(w));}
//2
void jcqh()
{
int nn=4;int i=0;
int sum=1; int SUM=0;printf(" :
");
for(i=1;i<=nn;i++){sum*=i;SUM+=sum;} printf("%d
",SUM);
}
//3
void swap(int*x,int *y) { if(*y!=*x){*y=*x^*y;*x=*x^*y;*y=*x^*y;}}
void r_array(int a[],int nn){int f,l; for(f=0,l=nn-1;f<=l;f++,l--)swap(&a[f],&a[l]);}
void display(int a[],int nn){int i;for(i=0;i<nn;i++)printf("%2d",a[i]);printf("
");}
void swap_array() { int a[6]={1,2,3,4,5,6};int m=6; printf("(swap):
");r_array(a,m); display(a,m);}
//4
void mppx(int v[],int nn)
{ int i=0,j=0,t=0;
for(i=0;i<nn;i++)
{
for(j=0;j<nn-1-i;j++) { if(v[j]>v[j+1]) {t=v[j+1];v[j+1]=v[j];v[j]=t;} }
}
}
void display1(int a[],int nn){int i;for(i=0;i<nn;i++)printf("%2d",a[i]);printf("
");}
void paixu_array(){ int x[9]={1,3,5,7,9,2,4,6,8}; printf(" :
"); mppx(x,9); display1(x,9); }
//5
void qiuandhoutao()
{
double hight=100.0,sum=0.0;
int day=9,tao=1,i,nn=0;
printf(" :
");
while(hight>0.01) {hight=hight/2;++nn;}
hight=100;
for(i=1;i<=nn;i++) {sum=sum+2*hight; hight=hight/2;} printf("sum=%f
",sum-100);
while(day) { tao=2*(tao+1); day--;} printf("tao=%d
",tao);
}
//6
void dis(int x[][n])
{
int i=0;int j=0;
for(i=0;i<n;i++)//for , ,
{
for(j=0;j<n;j++){printf("%4d",x[i][j]);}
printf("
");
}
}
void findout(int x[][n]){}
void migong()
{
int x[n][n]={0};int r,c,m;
m=n*n/4;
time_t t;
srand((unsigned)time(&t));
while(m)
{
r=rand()%6; c=rand()%4;
x[r][c]=1;x[0][0]=0;
m--;
}
//printf("%d
",m);
printf("
");
dis(x);
findout(x);
}
int jc(int x){int i=1;int ret=1;for(;i<=x;i++) ret*=i;return ret;}
int c(int m,int l){return(jc(m)/(jc(l)*jc(m-l)));}
int pw(int x){int i=1;int ret=1;for(;i<=x;i++) ret*=2;return ret;}
void fuzipaidui()
{
int nn=3; int i=0;
int flag=-1; int kinds=jc(2*nn);
printf(" :
");
for(i=1;i<=nn;i++) {kinds+=flag*jc(2*nn-i)*pw(i)*c(nn,i);flag=-flag;}
printf("kinds=%d
",kinds);
}
void zArray()
{int bz=0; int x[N][N]={0}; int i=0,j=0;
x[0][0]=0;
printf(" Z :
");
while(bz<N-2)//N=4,bz<N-1
{
if(bz%2==0)
{
x[i+1][0]=x[i][0]+1;i++;
while(i>0) {x[i-1][j+1]=x[i][j]+1;i--;j++;}
bz++;
}
if(bz%2==1)
{
x[0][j+1]=x[0][j]+1;j++;
while(j>0) {x[i+1][j-1]=x[i][j]+1;i++;j--;}
bz++;
}
}
//
x[N-1][0]=x[N-2][0]+1;
i=N-1;j=0;
while(i>0)
{
i--;j++;
x[i][j]=x[i+1][j-1]+1;
}
bz=0; x[N-1][N-1]=N*N-1;i=N-1;j=N-1;
//
while(bz<N-2)
{
if(bz%2==0) //
{
x[i-1][j]=x[i][j]-1;i--;
while(i<N-1) {x[i+1][j-1]=x[i][j]-1;i++;j--;}
bz++;
}
if(bz%2==1)//
{
x[i][j-1]=x[i][j]-1;j--;
while(j<N-1) {x[i-1][j+1]=x[i][j]-1;i--;j++;}
bz++;
}
}
dis(x);
}
//7
void xitong_time( void )
{
time_t t = time(0); char tmp[64];
printf(" :
");
strftime( tmp, sizeof(tmp), "%Y/%m/%d %X %A %j %z",localtime(&t) );
puts( tmp );
}
void jzqh()
{
int x[5][5]={0};
int i=0,j=0;
int sum1=0,sum2=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++){ x[i][j]=i*j;}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++){ if(i==j) sum1+=x[i][j];if(i+j==4) sum2+=x[i][j];}
}
dis(x);
printf(" =%3d, =%3d
",sum1,sum2);
}
void main()
{
int x=18;int y=12;int xy=x*y;int r=x; if(x<y){x=x^y;y=x^y;x=x^y;}
while(r) { r=y%x; y=x; x=r; }
printf("(x,y)=%3d
", y);
printf("(x,y)=%3d
", xy/y);
jzqh();
xitong_time();
zArray();
fuzipaidui();
migong();
swap_array();
paixu_array();
jcqh();
neicunduiqi();
}