阅读背景:

《C语言程序设计(苏小红版)》课后习题

来源:互联网 

习题11: 

//习题11
//11.1 
#include<stdio.h>
int main()
{
	int a[]={1,2,3,4,5};
			 0 1 2 3 4
	int *p=a;
	printf("%d\n",*p);//1 0
	printf("%d\n",*(++p));//2 1
	printf("%d\n",(*p)++);//2 1
	printf("%d\n",*p);//3 1
	printf("%d\n",*p--);//3 1
	printf("%d\n",*p);//2 0 1
	printf("%d\n",--(*p));//1 0 0 
	printf("%d\n",*p);//1 0 0
	
}
//11.2 (1)------------------------------------------------------正在提问/12/20------提问完成
#include<stdio.h>
void Print(const char *arr[],int len);
int main()
{
	const char *pArray[]={"How","are","you"};
//	char* pStr="hell";
//	char ch[]="hell";
	/*数组名不占存储空间,仅仅是一段内存的地址。
	而指针变量占用存储空间,其内容指向另一段内存空间。
	sizeof取的是内存空间的大小,传入变量时只能取得变量本身的大小,
	传入数组名时,则取得数组的大小。还有,sizeof和strlen是有区别的,
	原因在于strlen内部是以'

习题11: 

//习题11
//11.1 
#include<stdio.h>
int main()
{
	int a[]={1,2,3,4,5};
			 0 1 2 3 4
	int *p=a;
	printf("%d\n",*p);//1 0
	printf("%d\n",*(++p));//2 1
	printf("%d\n",(*p)++);//2 1
	printf("%d\n",*p);//3 1
	printf("%d\n",*p--);//3 1
	printf("%d\n",*p);//2 0 1
	printf("%d\n",--(*p));//1 0 0 
	printf("%d\n",*p);//1 0 0
	
}
//11.2 (1)------------------------------------------------------正在提问/12/20------提问完成
#include<stdio.h>
void Print(const char *arr[],int len);
int main()
{
	const char *pArray[]={"How","are","you"};
//	char* pStr="hell";
//	char ch[]="hell";
	/*数组名不占存储空间,仅仅是一段内存的地址。
	而指针变量占用存储空间,其内容指向另一段内存空间。
	sizeof取的是内存空间的大小,传入变量时只能取得变量本身的大小,
	传入数组名时,则取得数组的大小。还有,sizeof和strlen是有区别的,
	原因在于strlen内部是以'\0'作为字符串的结束
	*/ 
	//printf("%d\n",sizeof(pStr));//字符指针的大小 
	//printf("%d\n",sizeof(ch));//输出的一定是5:数组的大小 
	int num = sizeof(pArray)/sizeof(void*);
//	printf("%d",sizeof(void*));
	
	printf("Total string numbers = %d \n",num);
	Print(pArray,num);
	return 0;
	
}
void Print(const char *arr[],int len)
{
	int i;
	for(i=0;i<len;i++)
	{
		printf("%s ",arr[i]);
		//printf("%d",i);
	}
	printf("\n");
}
//11.2 (2)
#include<stdio.h>
void InputArray (int *pa,int n);
void OutputArray(int *pa,int n);
int main()
{
	int a[5];
	printf("Input five numbers:\n");
	InputArray(a,5);
	OutputArray(a,5);
	return 0;
}
void InputArray(int *pa,int n)
{
    /*
		for(;pa<pa+n;++pa)
		{
			scanf("%d",pa);
		}
		pa与pa+n同时增加一 
	*/
    	for(int i = 0 ;i<n;++i)
		{
			scanf("%d",pa+i);
		}
}
void OutputArray(int *pa,int n)
{
	for(int i=0;i<n;++i)
	{
		printf("%4d",*pa+i);
	}
	printf("\n");
}
//11.2(3)输入n门课程计算总分平均分 
/*
	一维指针即使里面放的是地址,也不能用二维的方式进行操作
	https://bbs.csdn.net/topics/370086928
*/
#include<stdio.h>
#define STUD 30
#define COURSE 5
void Total(int *score,int sum[],float aver[],int m,int n);
void Print(int *score,int sum[],float aver[],int m,int n);
int main()
{
   int i,j,m,n,score[STUD][COURSE],sum[STUD];
   float aver[STUD];
   printf("How many students?");
   scanf("%d",&m);
   printf("How many courses?");
   scanf("%d",&n);
   printf("Input score:\n");
   for(i =0;i<m;i++)
   {
   	 	for(j=0;j<n;j++)
   	 	{
   	 		scanf("%d",&score[i][j]);
   	 		
		}
   }
   /*
   for(i =0;i<m;i++)
   {
   	 	for(j=0;j<5;j++)
   	 	{
   	 		printf("%d ", score[i][j]);
   	 		printf("=%d ", &score[i][j]);
   	 		
		}
		printf("\n");
   }*/
  // printf("*score=%d\n",**score);
   Total(*score,sum,aver,m,n);
   Print(*score,sum,aver,m,n);
   return 0;
}
void Total(int *pScore,int sum[],float aver[],int m,int n)
{
	int i,j;
	for(i=0;i<m;i++)
	{
		sum[i]=0;
		for(j=0;j<n;j++)
		{
			sum[i] = sum [i]+pScore[i*COURSE+j];
		//	printf("pScore[i*n+j]=%d\n",pScore[i*COURSE+j]);//行指针未赋值 
		}
		aver[i] = (float)sum[i]/n;
	}
}
void Print(int *pScore,int sum[],float aver[],int m,int n)
{
	int i,j;
	printf("Result:\n");
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)
		{
			printf("%4d\t",pScore[i*COURSE+j]);
		}
		printf("%5d\t%6.llf\n",sum[i],aver[i]);
	}
}
//11.4输出矩阵转置nXn
#include<stdio.h>
#include<stdlib.h>
#define N 20
void tran_spose1(int a[][N],int n);
void tran_spose2(int (*a)[N],int n);
void tran_spose3(int *a,int n);
int main()
{
	int n;
	int i,j;
	int number[N][N]={0}; 
	printf("please enter the scale of your matrix:");
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			scanf("%d",&number[i][j]);
			//printf("%d ",number[i][j]);
		}
	}
	tran_spose3(*number,n);
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			printf("%d ",number[i][j]);
		}
		printf("\n");
	}
 } 
 void tran_spose3(int *a,int n)
 {
 	int swap = 0;
 	int *flag =NULL;
 	flag = (int *)calloc(n*n,sizeof(int));
 	if(flag==NULL)
 	{
 		printf("no enough room");
 		exit(1);
	 }
 	for(int i=0;i<n;i++)
 	{
 		for(int j =0;j<n;j++)
 		{
 			if((i!=j)&&(flag[i*n+j]==0))
 			{
 				flag[i*n+j]=1;
 				flag[j*n+i]=1;
	 			swap = a[i*N+j];
		 		a[i*N+j]=a[j*N+i];
		 		a[j*N+i]= swap;
			 }
		 }
	}
	free(flag);
 }
 void tran_spose2(int(*a)[N],int n)
 {
 	int swap = 0;
 	int *flag =NULL;
 	flag = (int *)calloc(n*n,sizeof(int));
 	if(flag==NULL)
 	{
 		printf("no enough room");
 		exit(1);
	 }
 	for(int i=0;i<n;i++)
 	{
 		for(int j =0;j<n;j++)
 		{
 			if((i!=j)&&(flag[i*n+j]==0))
 			{
 				flag[i*n+j]=1;
 				flag[j*n+i]=1;
	 			swap = *(a+i)[j];
		 		*(a+i)[j]=*(a+j)[i];
		 		*(a+j)[i] = swap;
			 }
		 }
	}
	free(flag);
 }
void tran_spose1(int a[][N],int n)
 {
 	int swap = 0;
 	int *flag =NULL;
 	flag  = (int *)calloc(n*n,sizeof(int));
 	if(flag==NULL)
 	{
 		printf("no enough room");
 		exit(1);
	 }
 	for(int i=0;i<n;i++)
 	{
 		for(int j =0;j<n;j++)
 		{
 			if((i!=j)&&(flag[i*n+j]==0))
 			{
 				flag[i*n+j]=1;
 				flag[j*n+i]=1;
	 			swap = a[i][j];
		 		a[i][j]=a[j][i];
		 		a[j][i] = swap;
			 }
		 }
	}
	free(flag);
 } 
 //11.4输出矩阵转置nXm
#include<stdio.h>
#include<stdlib.h>
#define N 20
void tran_spose1(int a[][N],int n,int m);
void tran_spose2(int (*a)[N],int n,int m);
void tran_spose3(int *a,int n,int m);
int main()
{
	int n,m;
	int i,j;
	int number[N][N]={0}; 
	printf("please enter the scale of your matrix(nXm):");
	scanf("%d",&n);
	scanf("%d",&m);
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			scanf("%d",&number[i][j]);
			//printf("%d ",number[i][j]);
		}
	}
	tran_spose2(number,n,m);
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)
		{
			printf("%d ",number[i][j]);
		}
		printf("\n");
	}
 } 
 void tran_spose3(int *a,int n,int m)
 {
 	int swap = 0;
 	int *flag =NULL;
 	int max;
 	max = n>m ? n:m;
 	flag  = (int *)calloc(max*max,sizeof(int));
 	
 	if(flag==NULL)
 	{
 		printf("no enough room");
 		exit(1);
	 } 
	 
 	for(int i=0;i<max;i++)
 	{
 		for(int j =0;j<max;j++)
 		{
 			if((i!=j)&&(flag[i*max+j]==0))
 			{
 				flag[i*max+j]=1;
 				flag[j*max+i]=1;
 				
	 			swap = a[i*N+j];
		 		a[i*N+j]=a[j*N+i];
		 		a[j*N+i]= swap;
			 }
		 }
	}
	free(flag);
 }
 void tran_spose2(int(*a)[N],int n,int m)
 {
 	int swap = 0;
 	int *flag =NULL;
 	int max;
 	max = n>m ? n:m;
 	flag  = (int *)calloc(max*max,sizeof(int));
 	if(flag==NULL)
 	{
 		printf("no enough room");
 		exit(1);
	 }
 	for(int i=0;i<max;i++)
 	{
 		for(int j =0;j<max;j++)
 		{
 			if((i!=j)&&(flag[i*max+j]==0))
 			{
 				printf("(。^▽^)\n");
 				flag[i*max+j]=1;
 				flag[j*max+i]=1;
	 			swap = *(a+i)[j];
		 		*(a+i)[j]=*(a+j)[i];
		 		*(a+j)[i] = swap;
			 }
		 }
	}
	free(flag);
 }
void tran_spose1(int a[][N],int n,int m)
 {
 	int swap = 0;
 	int *flag =NULL;
 	int max;
 	max = n>m ? n:m;
 	flag  = (int *)calloc(max*max,sizeof(int));
 	if(flag==NULL)
 	{
 		printf("no enough room");
 		exit(1);
	 }
 	for(int i=0;i<max;i++)
 	{
 		for(int j =0;j<max;j++)
 		{
 			if((i!=j)&&(flag[i*max+j]==0))
 			{
 				flag[i*max+j]=1;
 				flag[j*max+i]=1;
	 			swap = a[i][j];
		 		a[i][j]=a[j][i];
		 		a[j][i] = swap;
			 }
		 }
	}
	free(flag);
 } 

习题7: 

//[7.1]分析并写出下列程序的结果 
#include<stdio.h>
int Squre( int i)
{
	printf("4 %d,",i);
	return i*i;
} 
int main()
{
	int i = 0;
	i = Squre(i);
	for(;i< 3;i++)
	{
		printf("1 %d,",i);
		static int i = 1;
		printf("2 %d,",i);
		i+= Squre(i);
		printf("3 %d,\n",i);
	}
	printf("%d\n",i);
	return 0;
}
	//输出:2,6,42,3
 /*静态局部变量是在编译时赋初值的,
		且只赋初值一次,在程序运行时它已有初值。
		以后在每次调用函数时就不再重新赋初值,
		而是保留上次函数调用结束时的值
		*/

//[7.2]用全局变量模拟数字式时钟
#include<stdio.h>
int hour,minute,second;/*定义全局变量*/

void  Update()
{
	second++;
	if(second == 60)
	{
		second = 0;
		minute++;
		
	}
	if(minute == 60)
	{
		minute = 0;
		hour++;
		
	}
	if(hour == 24)
	{
		hour = 0;
		
	}
}
void Display()
{
	printf("%d-%d-%d\n",hour,minute,second);
	
}
void Delay()
{
	int t;
	for(t=0;t<1e8;t++);
	
}
int main()
{
	int t;
	//int hour, minute,second;
	  hour=minute=second=0;
	//用循环体控制时钟运行时间 
	for( t=0;t<1e6;t++)
	{
		Update ();
		Display ();
		Delay();	
	
	}
	return 0;
}
//[7.3]计算两书最大值
#include<stdio.h>
int c_max(int a,int b)
{
	return a>b ? a:b;

}
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	printf("最大值:%d\n",c_max(a,b));
	return 0;
}
//[7.4]计算最小公倍数
#include<stdio.h>
int Common_m( int i,int j)
{
	int c,r,swap,n,m;
	n = i;
	m = j;
	//最小公倍数=两整数的乘积÷最大公约数
	if(i<j)
	{
		swap = i;
		i = j;
		j = swap;
	}
	while(c != 0)
	{
		c = i%j;
		i = j;
		j = c;
		printf("i2 %d\n",i);

	}
	printf("i1 %d\n",i);
	return (n*m)/i ;
}
int main()
{
	int a,b,r;
	printf("请输入值: ");
	scanf("%d%d",&a,&b);

	r = Common_m(a,b);

	printf("最小公倍数:%d",r);

	return 0;
}
//[7.5 && 7.6]计算1-n的阶乘
#include<stdio.h>
int main()
{
	int sum();
	int flag,n1;
	printf("请输入n:");
	scanf("%d",&n1);

	flag = sum(n1);
	printf("1!+2!+3!+……+n! = %d",flag);
}
//求和
int sum(int n2)
{
	int mul();
	int i,r=0;
	for(i = 1;i<= n2 ;i++)
	{
		r += mul(i);
	}

	return r;
}
//阶乘函数
int mul(int n3)
{
	int i;
	int m = 1;
	for(i =1;i<= n3 ;i++)
	{
		m = m*i;
	}
	printf("%d!= %d \n",i-1,m);
    return m;
}
//[7.7]求最大公约数
#include<stdio.h>
int main()
{
    int Ged3();
    int a,b;
    printf("请输入你要算的两个数:");
    scanf("%d%d",&a,&b);
    Ged1(a,b);
    return 0;

}
int Ged1(int a,int b)//穷举法
{
    int t ,i,flag = 0;
    t= a<b ? a:b ;
    for(i = t;i> 0 ;i-- )
    {
        if((a%i==0)&&(b%i==0) )
        {
            flag=1;
            break;
        }

    }
    if(flag)
    {
        printf("最大公约数:%d\n",i);

    }
    else
    {
        printf("没有最大公约数!\n");
    }
    return 0;
}
int Ged2(int a,int b)//欧几里得算法
{
    int swap,c;
    if(a<b)
    {
        swap =  a;
        a = b;
        b = swap;
    }
    while(c != 0)
    {
        c = a%b;
        a = b;
        b = c;
    }
    return a;
}
int Ged3(int a,int b) //递归方法
{
    int swap;
    if(a<b)
    {
        swap = a;
        a = b;
        b = swap;
    }
    if(a=b)
    {
        return a;
    }
    else
    {
        Ged3(a-b,b);
    }

}

¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥
//[7.8]水手与猴子
#include <stdio.h>
#include <math.h>
int main()
{

	int i;
	double k,x,y;
	i=1;k=1.0;y=k;
	while(i<=5)
	{
		i++;
		y=(4*y-1)/5;             //y=藏得椰子数  5y1+1=4y2 y为藏的 
		if(y!=floor(y))//floor(y) 去下整,就是去掉小数部分 y不是整数 
		{

			k=k+1.0;
			y=k;
			i=1;
			//刷新初始值 
		}
	}
	//找到我的正确初始值 
	x=5*k+1;
	printf("k=%d\n",k); 
	printf("%d个水手分椰子,原有椰子至少有:%6.0f个\n",5,x);

}



//[7.9]计算五个老哥的年龄
#include<stdio.h>
int age(int i)
{
    int n;
    if(i==1)
    {
        printf("10\n");
        return 10;
    }
    else
    {
        n = 2+age(--i);
        printf("%d\n",n);
        return n;
    }
    return 0;
}
int main()
{
    age(5);
}
//[7.10]魔术师猜数字
#include<stdio.h>
int order(int num)
{

    int a[5],b,sum = 0,i,j,z;

    i = num / 100 ;
    j = num % 10 ;
    z = num / 10 - i* 10 ;

    a[0] = i*100+j*10+z;
    a[1] = j*100+i*10+z;
    a[2] = j*100+z*10+i;
    a[3] = z*100+j*10+i;
    a[4] = z*100+i*10+j;
    for(b=0;b<5;b++)
    {
       sum += a[b];
    }
     return sum;
}

int main()
{
    int num,sum,i;
    scanf("%d",&num);
    for(i=100;i<1000;i++)
    {
        if( num == order(i))
       {
           printf("你的数字是%d\n",i);
           break;
       }

    }
    if(i >= 1000)
    {
        printf("你算错了!");
    }
       return 0;
}
//[]
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int exame(int i,int *j)
{
    if(( i + *j ) == 30)
    {
        *j = 1;
        return 0;
    }
    else
    {
        return 1;
    }
}
int main()
{
	srand((unsigned int )time(NULL));
	int i = rand()%100+1;
	int *c=NULL,flag=1,*user=NULL,last,end=0,key;
	while(key)
	{

        if(i%2)//计算机开始
        {
                last = 30-end;
                if(last%3==1)
                {
                    *c = rand()%100/4;
                    printf("%d\n",*c);
                }
               else if(last%3==2)
               {
                    *c = rand()%100/4;
                    printf("%d ",*c);
                    printf("%d\n",*c+1);
                    *c =*c+*c+1 ;
                }
                else
                {
                      while(flag<=(rand()%2+1))
                      {
                          if(flag==1)
                          {
                              *c = rand()%100/4;
                              printf("%d\n",*c);
                              break;
                          }
                          else
                          {
                            *c = rand()%100/4;
                            printf("%d ",*c);
                            printf("%d\n",*c+1);
                            *c =*c+*c+1 ;
                            break;
                           }

                      }
                      key = exame( end,c);
                      end += *c;
             }
        }
        else//人报数
        {
            printf("please input your number:");
            scanf("%d",*user);
            key = exame(end,user);
            end += *user;
        }
	}
	if(*c == 1)
    {
        printf("the computer is the winner!game over!");
    }
    else if(*user == 1)
    {
        printf("you are the winner!");
    }
    else
    {
        printf("404");
    }
	return 0;
}
//7.14汉诺塔
#include<stdio.h>
int haino(int n,char a,char b,char c);
int main()
{
	printf("Please input the scale of haino:");
	int n;
	scanf("%d",&n);
	haino(n,'A','B','C');
 }
 int haino(int n,char a,char b,char c)
 {
 	if(n==1)
 	{
 		printf("%c->%c\n",a,c);
	 }
	 else
	 {
	 	haino(n-1,a,c,b);
	 	printf("%c->%c\n",a,c);
	 	haino(n-1,b,a,c);
	 }
	 return 0;
 }

习题6:


//P138 习题6
//6.1
//(1) 【正确】
#include<stdio.h>
int main()
{
	int i,j,k;
	char space = ' ';
	for(i =1;i<=4;i++)
    {
        for(j = 1;j<=i;j++)
        {
           printf("%c",space);

        }
        for(k = 1;k<=6;k++)
        {
            printf("*");
         }
        printf("\n");
    }
}

//(2)【正确】

#include<stdio.h>
int main()
{
	int k = 4,n;
	for( n = 0; n<k ; n++ )
	{
		if( n %2 == 0 ) continue;
		k--;
	}
	printf("k = %d,n = %d\n",k,n);
}

//(3)【正确】

#include<stdio.h>
int main()
{
	int k  =4,n;
	for(n =0;n<k;n++)
	{
        if(n%2 == 0) break;
        k--;
	}
	printf("k = %d,n=%d\n",k,n);

}

//6.2
//(1)计算1+3+5+7...+99+101的值【正确】

#include<stdio.h>
main()
{
	int i,sum = 0;
	for(i= 1;i<=101;i+=2)
	{
		sum += i;
	}
	printf("sum = %d\n",sum);
}

//(2)计算1*2*3+3*4*5+...+99*100*101的值.

#include<stdio.h>
main()
{
	long i ;
	long term,sum=0;
	for (i=1;i<=100;i+=2)
	{
	     term = i*(i+1)*(i+2);
	     printf("%d =%d*%d*%d\n",term ,i,i+1,i+2);
         sum = sum+term;
	}
	printf("sum = %1d",sum);
}

//(3)计算a+aa+aaa+……+aa…a(n个a)的值,n和a的值由键盘输入

#include<stdio.h>
main()
{
	long term = 0,sum = 0;
    int a,i,n;
	printf("Input a,n:");
	scanf("%d %d",&a,&n);
	for(i=1;i<=n;i++)
	{
		term = term*10+a;
		sum = sum+term;

         }
	printf("sum = %1d\n",sum);

}

//(4)1/1-1/2+1/3+……+1/99-1/100

#include<stdio.h>
#include<math.h>
main()
{
	int n = 1;
    float term = 1.0 , sign = 1, sum = 0;
	while(fabs(term) >= 1e-2 )
	{
		term = pow(-1,n-1)*(sign/n);
		printf("%f\n",term);
		sum = sum+term;
		sign = 1;
		n++;
	}
	printf("sum = %f\n",sum);
}

//(5)计算sinx的值

#include <math.h>
#include <stdio.h>
int main()
{
    int n=1,count=1;
    double x,term,sum;
    scanf("%lf",&x);
    term = x;
    sum = x;
    do{
        term= -term*x*x/((n+1)*(n+2));
        sum +=term;
        n=n+2;
        count++;
    }while(fabs(term)>=1e-5);  //注意10^-5的表达
    printf("sin(x)=%lf,count=%d",sum,count);
    return 0;
}

//【6.3】
//程序改错

#include<stdio.h>
main()
{
	int x = 1,find =0;
 //while(!find);
 for(;x<1000;x++)
	{
		if(x%2==1 && x%3 ==2 && x%5==4 && x%6==5 && x%7==0)
			{
				printf("x=%d\n",x);
			//   find = 1;
				continue;
			} 
		}
}

//【6.4】计算并输出1到N之间所有的数平方和立方

#include<stdio.h>
#include<math.h>
main()
{
	long i, n;
	printf("请输入n:");
	scanf("%ld",&n);
	//求平方和			
	for( i=1; i<n ; i++)
	{
			printf("%ld的平方是%ld  ",i,i*i);
			printf("%ld的立方是%ld\n",i,i*i*i);			
	}			
		
}

//【6.8】

#include<stdio.h>
#include<math.h>
main()
{
	double term=1,sum=0,i=1;
  	int j=0;
  do
  {
				term = 1/ i ; 
     sum += pow(-1,j)*term;
     j++;
     i += 2;

   }while(fabs(term)>1e-4);
			sum *=4;
			printf("%lf %d",sum,j);
}

//【6.9】
//计算E的近似值,输出E的值并累加的项数
#include<stdio.h>
#include<math.h>
int main()
{
	double e,sum=1,term=1,i;
	int count=1;
    do
    {
		term = term*count;
        sum += 1/term;
        count++;
    }while(fabs(1/term)>=1e-5);
    printf("e=%.2lf, 共累加了:%d",sum,count-1);
    return 0;
}

//【6.10】
//计算水仙花数
#include<stdio.h>
#include<math.h>
int main()
{
	int a,b,c,i,num=0;
    for(i=100;i<1000;i++)
    {
    	 a = i / 100;//百位
         c = i % 10;//个位
         b = i /10-a*10;//十位
		num = pow(a,3)+pow(b,3)+pow(c,3);
        if( num == i )
        {
        		printf("%d\n",i);
        }
      
    } 
    return 0;
}


//【6.11】
//1!+2!+……+m!<n,计算m的值,给定一个N
#include<stdio.h>
int main()
{
	int n,i=1,term=1,flag=0;
	printf("请输入个N值:");
	scanf("%d",&n);
	while(1)
	{
		term = term*i;
		//printf("term = %d ,i = %d\n",term,i);
		flag +=term;
		if( flag >= n )
		{
			 break;
		  }
		i++;	 
	}	
	 printf("M=%d",i-1);
	 return 0;
}

//【6.12】
//输入一些正数,输出和,输入负或零退出
#include<stdio.h>
int main()
{
	int i,sum;
    printf("输入一些正数,输出和,输入负或零退出\n");
    while(1)
    {
      scanf("%d",&i);
      if( i >0)
      {
    		printf("已录入数字%d,请继续输入\n",i);
      		sum+=i;
    	}
	 else
	 {
			break;
		}	
    }
    printf("sum=%d",sum);
    return 0;


}//【6.13】
//输入整数,正数求和,负数跳过
#include<stdio.h>
int main()
{
			int i,sum;
			printf("*****输入0退出******\n");
			while(1)
			{
				scanf("%d",&i);
				if( i==0 )
				{
								break;
					}
				else if( i < 0)
				{
								printf("请输入正数\n");
								continue;
					}
				else
				{
							printf("已输入数字%d,请继续\n",i);
							sum += i;
         }
			}
    printf("sum = %d",sum);
    return 0;
}





//【6.14】
//马克思手稿,用穷举法计算男人,女人,小孩
#include<stdio.h>
int main()
{
    int man,wonman,kid,sum,money;
    for(man=0;man<30;man++)
  	{
   	   	for(wonman=0;wonman<30;man++)
		{	for(kid=0;kid<30;kid++)
			{	sum=man+wonman+kid;
				if( sum==30 )
					{
				     	money = man*3+wonman*2+kid*1;
                         if(money==50)
                           {
                           printf("男人:%d人,女人:%d人,小孩:%d人\n",man,wonman,kid);
                           }
	、		         	}
             }
        }
   }



    printf("Hello world!");
    return 0;
}
//【6.15】
//鸡兔同笼问题 

#include<stdio.h>
main()
{
	int chook,hare,sum,t,j;
	for(chook=0;chook<98;chook++)
	{
		for(hare=0;hare<98;hare++)
		{
			sum = chook+hare;
			if(sum == 98)
			{
				j = chook*2+hare*4;
				if(j==386)
				{
					printf("鸡有%d只,兔有%d只",chook,hare);
				}
			}
			
		}
		
	} 
	
} 
//【6.16】
//<张秋建算经>问题
#include<stdio.h>
main()
{
	int man,wonmen,kid,sum,money;
	for(man=0;man<100;man++)
	{
		for(wonmen=0;wonmen<100;wonmen++)
		{
				for(kid=0;kid<100;kid++)
				{
					sum = man+wonmen+kid;
						if(sum == 100)
						{
							money=man*5+wonmen*3+kid/3;
							if(money==100)
							{
								printf("公鸡%d只,母鸡%d只,小鸡%d只\n",man,wonmen,kid);
							}
						}
				}
		}
	}
	
}
//【6.17】
//换钱问题
#include<stdio.h>
main()
{
	int ten,five,one,sum;
	for(ten=0;ten<10;ten++)
	{
		for(five=0;five<20;five++)
		{
			for(one=0;one<100;one++)
			{
				sum = ten*10+five*5+one;
				if(sum == 100)
				{
					printf("十元有%d张,五元有%d张,一元有%d张\n",ten,five,one);
				}
			}
		}
	}
	
} 
//【6.18】
//输出九九乘法表 
#include<stdio.h>
main()
{
	int i,j,num; 
	printf("1   2   3   4   5   6   7   8   9\n");
	printf("-   -   -   -   -   -   -   -   -\n");
	for(i=1;i<10;i++)
	{
		for(j=1;j<10;j++)
		{
			num = i*j;
			printf("%-4d",num);
									 
		}
		printf("\n");
	} 

}

//【6.18】
//输出九九乘法表 

#include<stdio.h>
main()
{
	int i,j,num; 
	printf("1   2   3   4   5   6   7   8   9\n");
	printf("-   -   -   -   -   -   -   -   -\n");
	for(i=1;i<10;i++)
	{
		for(j=1;j<10;j++)
		{
			num = i*j;
			printf("%-4d",num);
									 
		}
		printf("\n");
	} 

}
/*************************/
/*************************/
#include<stdio.h>
main()
{
	int i,j,num; 
	printf("1   2   3   4   5   6   7   8   9\n");
	printf("-   -   -   -   -   -   -   -   -\n");
	for(i=1;i<10;i++)
	{	
		
		for(j=1;j<=i;j++)
		{
			num = i*j;
			printf("%-4d",num);
		    			
									 
		}
		printf("\n");
	} 

}
/******************************/
/*****************************/
//与第三种刚好相反 
#include<stdio.h>
main()
{
	int i,j,num; 
	printf("1   2   3   4   5   6   7   8   9\n");
	printf("-   -   -   -   -   -   -   -   -\n");
	for(i=1;i<10;i++)
	{	
		
		for(j=1;j<=10-i;j++)
		{
			num = i*j;
			printf("%-4d",num);
		    			
									 
		}
		printf("\n");
	} 

}
/***********************************/
/************************************/
#include<stdio.h>
main()
{
	int i,j,num,k; 
	printf("1   2   3   4   5   6   7   8   9\n");
	printf("-   -   -   -   -   -   -   -   -\n");
	for(i=1;i<10;i++)
	{	
		
		for(j=i;j<=9;j++)
		{
			num = i*j;
			printf("%-4d",num);							 
		}
		printf("\n");
		for(k=0;k<i;k++)
		{
			printf("    ");
		}
	} 

}
//【6.19】
//百万富翁与陌生人
#include<stdio.h>
main()
{
	int i,strenger=0;
	float richer=0.01;
	for(i=1;i<30;i++)
	{
		strenger += 100000*i;
		//陌生人给富翁的 
		richer += richer*2;
		//富翁给陌生人的 
		//printf("%d %d %f\n",i,strenger,richer);
	}
	printf("陌生人给富翁%d元,富翁给陌生人%f元。\n",strenger,richer);
	 
} 
//【6.20】
//抓肇事逃逸犯
#include<stdio.h>
main()
{
	int a,b,c,d,num,i;
	for(a=0;a<10;a++)
	{
		for(c=0;c<10;c++)
		{
			b=a;
			d=c;
			if( a != c )
			{
				num = a*1000+b*100+c*10+d;
				for( i = 10 ; i < 100 ; i++ )
				{
					if( num == i*i )
					{
						printf("车牌号是:%d\n",num);
					}
				}
			}	
			
		}
	}
	
} 
//【6.21】
//laolao观众想要听礼炮(*≧︶≦))( ̄▽ ̄* )ゞ。
 #include<stdio.h> 
 main()
 {
 	int i,sum=63;
	bool a,b,c;
 	for(i=1;i<147;i++)
	{
		a = (i%5 == 0)&&(i%6 == 0);
		b = (i%5 == 0)&&(i%7 == 0);
		c = (i%7 == 0)&&(i%6 == 0);
		if( c || a || b )
		{
			
			sum -= 1;
		}
	}
	printf("laolao可以听到%d声炮响\n",sum);
 	
 }
 /***************************************************************/
 /*                      本章实验题                             */
 /***************************************************************/
//国王的许诺
//直接累加 
#include<stdio.h>
#include<math.h>
main()
{
	long i;
	long sum = 0 ;
	for(i=1;i<65;i++)
	{
		printf("%ld %ld\n",i,sum);
		sum  += pow(2,i-1);
	} 
	printf("笨蛋国王给腹黑国师%ld颗麦子\n",sum);
	//18446744073709552000.000000
}
//数学方法 
#include<stdio.h>
#include<math.h>
int main()
{ 
     float  i = 1,sum = 0;
	 sum = i*(1-pow(2,64))/(1-2);
	printf("%.2f",sum);
	//18446744073709552000.00
} 
//小学生计算机辅助教学系统 
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>

int main()
{
	int account5();
	account5();
	
}
/**********************************************************************************************/
void remind(int a)
{
	char *reminder1[4]= {"Very good!","Excellent!","Nice work!","Keep up the good work!"};
	char *reminder2[4] = {"No. Please try again ","Wrong.Try once more","Don`t give up","Not correct.Keep trying."};
	srand((unsigned int) time(NULL));
	int i = rand() % 4 ;
	//随机生成4个数
	 if(a)
	{
		printf("%s",reminder1[i]);
	}
	else
	{
		printf("%s",reminder2[i]);
	
	}
	printf("\n");
}

/****************************************************************************************/
int account5()//任务5 
{
	int account1_4();
	int k,sum,flag=1;
	float rate;
	do{
		k = account1_4();
		rate =(float) k/10; 
	}while(fabs(rate)<0.75);
}
/**********************************************************************************/
int account1_4()//任务1-4 
{
	int op,a; 
	int swap;
	int i[10] , j[10] ,result[10],flag=0;
	float temp[10];
	char mid[] = {'+','-','*','/'};
	
	srand((unsigned int) time(NULL));
	for(a=0;a<10;a++)
	{
		i[a] = ((rand() %10) + 1); 
		j[a] = ((rand() %10) + 1); 
		op =   rand() % 4 ;
		//生产式子
		
		if(i[a]<j[a])
		{
			swap = i[a];
			i[a] = j[a];
			j[a] = swap;
		}
		//保证结果为正 
		
		switch(mid[op])
		{
			case '+':
				printf("%d + %d = ? ",i[a],j[a]);
				result[a]  = i[a] + j[a] ;break;
			case '-':
				printf("%d - %d = ? ",i[a],j[a]);
				result[a]  = i[a] - j[a] ;break;
			case '*':
				printf("%d * %d = ? ",i[a],j[a]);
				result[a]  = i[a] * j[a] ;break;
			case '/':
				printf("%d / %d = ? ",i[a],j[a]);
				result[a]  = i[a] / (j[a]*1.0) ;break;
			default:
				printf("404");
						
		}
		//计算正确值 
		
		scanf("%f",&temp[a]);
		//输入小朋友算的值 
		if (fabs( (float) result[a] - temp[a])<1e-4 )
		{
			remind(1);
			flag++;
		}
		else
		{
			remind(0); 
		} 
	}	
	printf("总分:%d ,正确率:%.2f\n ",flag*10 , flag / (10*1.0));
	return flag;	
}

习题8:

// 【 习 题 8 】
//8.1分析并写出结果
//(1)
#include<stdio.h>
void func(int x)
{
    x = 20;
}
int main()
{

        int x = 10;
        func(x);
        printf("%d",x);

    return 0;
}
#include<stdio.h>
void func(int b[])
{
    int j;
    for(j=0;j<4;j++)
    {
        b[j]=j;
    }
}
int  main()
{
    static int a[]= {5,6,7,8},i;
    func(a);
    for(i=0;i<4;i++)
    {
        printf("%d",a[i]);
    }
    return 0;
}
//8.2填适合的表达式
//(1)
//统计十个整数中,正数的个数
int positive_num(int a[],int n)
{
    int i,count = 0;
    for(i=0;i<n;i++)
    {
        if(a[i]>0)
            count++;

    }
    return count;
}
int main()
{
    int a[]={-2,-3,6,1,0,-4,-63,-5,-7,-8};
   printf("%d",positive_num(a,10));

    return 0;
}
//(2)迭代法算斐波那契数列
//迭代法也称辗转法,是一种不断用变量的旧值递推新值的过程
void fib(long f[],int n)
{
    int i;
    f[0] = 0;
    f[1] = 1;
    for(i=2;i<n;i++)
    {
        f[i] = f[i-1]+f[i-2];
    }
    return f;
}
int main()
{
    int i;
    int a[14]={0};
    fib(a,14);
    for(i=0;i<14;i++)
    {
        printf("%d\n",a[i]);
    }


    return 0;
}
//(3) 从键盘输入10个整数,计算最大最小 及下标
#include<stdio.h>
int main()
{
	int a[10],n,max,min,maxpos,minpos;
	for(n=0;n<10;n++)
	{
		scanf("%d",&a[n]);
	}	
	max = min = a[0];
	maxpos = minpos = 0;
	for(n=0;n<10;n++)
	{
		
		if(max<a[n])
		{
			max = a[n];
			maxpos =n;
			
		}
		else if(min>a[n])
		{
			min = a[n];
			minpos = n;
			
		}
	}
		printf("max = %d,pos = %d\n",max,maxpos);
		printf("min = %d,pos = %d\n",min,minpos);
	return 0;
 } 
 //(4)计算矩阵A与B之积 
#include<stdio.h>
#define ROW 2
#define COL 3
MultiplyMatrix(int a[ROW][COL],int b[COL][ROW],int c[ROW][ROW])
{
	int i,j,k;
	for(i=0;i<ROW;i++)
	{
		
		for(j=0;j<ROW;j++)
		{
			
			c[i][j] = 0;
			for(k=0;k<COL;k++)
			{
				c[i][j] += a[i][k]*b[k][j];
			}
		}
	}
	
 } 
 void PrintMatrix(int a[ROW][ROW])
 {
 	int i,j;
 	for(i=0;i<ROW;i++)
 	{
 		for(j=0;j<ROW;j++)
 		{
 			printf("%6d",a[i][j]);
		 }
		 printf("\n");
	 }
 }
int main()
{
	int a[ROW][COL],b[COL][ROW],c[ROW][ROW],i,j;
	printf("Input 2*3 matrix a:\n");
	for( i=0;i<ROW;i++)
	{
		for(j=0;j<COL;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	printf("Input 3*2 matrix b:\n");
	for(i=0;i<COL;i++)
	{
		for(j=0;j<ROW;j++)
		{
			scanf("%d",&b[i][j]);
		}
	}
	MultiplyMatrix(a,b,c);
	printf("Results:\n");
	PrintMatrix(c);
	return 0;
 } 
  //8.3分析并指正“返回一个数组中所有元素被第一个元素除的结果”<指出隐患> 
 #include<stdio.h>
void DivArray(float *pArry,int n)
{
	int i;
	if( pArry[0] != 0 )
	{		
		for(i=1;i<n;i++)
		{	
			pArry[i] /= pArry[0]; 
		
		}
			pArry[0] /= pArry[0]; 
	}
	else
	{
		printf("分母不为0!");
	}
	
  }
  int main()
  {
  	float a[5]={5,2,3,4,1};
  	int i;
  	DivArray( a ,5);
  	for(i=0;i<5;i++)
  	{
  			printf("%.2f\n",a[i]);
	}
  	return 0;
  }
//8.4 用函数编程统计不及格人数 
#include<stdio.h>
int main()
{
	int n,i,temp,count=0;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&temp);
		if(temp<60)
		{
			count++;
		}
		
	}
	printf("有%d人\n",count);
	return 0;
}
//8.5统计成绩高于平均分的学生人数
#include<stdio.h>
#define MAX 40 
int count_score(int a[],int b,int n)
{
	int i,count=0;
	for(i=0;i<n;i++)
	{
		if (a[i]>b)
		{
			count++;
		}
	}
	return count;
}
 int main()
 {
 	int n,i=0,sum=0;
	float ave=0;
 	int stu[MAX]={0};
 	do
 	{
 		scanf("%d",&stu[i]);
 		sum += stu[i];
		i++;
	}while(stu[i-1] >= 0);
	 ave = sum / i;
	 
	 printf("%d\n",count_score(stu,ave,i));
 }
//8.6 输入成绩和学号输出最高分和下标
#include<stdio.h>
#define	MAX 100
struct
{
	int num;
	char order[MAX];
}student[MAX];
int main()
{
	int i=0,le,k;
	do
	{
		scanf("%d",&student[i].num);
		getchar();
		scanf("%s",student[i].order);
		getchar();
	//	printf("%d %s\n",student[i].num,student[i].order );
		i++;
		
	 } while(student[i-1].num >= 0);
	 
	 le = i;
	 k = 0;
	 
	 for(i=0;i<le;i++)
	 {
	 	if(student[k].num<student[i].num)
		 {
		 	k=i;
		 }	
	 }
	 printf("%d %s",student[k].num,student[k].order );
	 
	return 0;
 }
//8.7输入10 个整数将最大与最小的互换 
#include<stdio.h>
#define N 10
int swap(int a[],int n);
int print_num(int a[],int n);
int main()
{
	int num[20]={0};
	int i;
	for(i=0;i<N;i++)
	{
		scanf("%d",&num[i]);
	}
	swap(num,N);
	print_num(num,N);
	return 0;
}
int swap(int a[],int n)
{
	int low,high,i,temp;
	low = high = 0;
	for(i=0;i<n;i++)
	{
		if( a[low]>a[i])
		{
			low = i;
		}
		if( a[high] < a[i])
		{
			high = i;
		}
	}
	
	temp = a[low];
	a[low] = a[high];
	a[high] =  temp; 
	
	return 0;
 } 
 int print_num(int a[],int n)
 {
 	int i;
 	for(i=0;i<n;i++)
 	{
 		printf("%d\n",a[i]);
	 }
 	return 0;
 }
 //8.8 餐饮打分并输出结果---------------【有误】
#include<stdio.h>
#define MAX 40 
void printbasis(struct a[],int n);
struct STU
{
	int grade;
	int score;
	
 }stu[MAX];
int main()
{
	int i,n;
	printf("please Enter the total number of students:");
	scanf("%d",&n);
	printf("please Enter the student's score(separated by spaces):");
	for(i=0;i<n;i++)
	{
		stu[i].grade = i+1;
		scanf("%d",&stu[i].score); 
	 }
	printbasis(stu,n);
	return 0;
 } 
 void printbasis(struct STU a[],int n)
 {
 	int i,j;
 	printf("\tGRADE \tCOUNT \tHISTOGRAM\n");
 	for(i=0;i<n;i++)
 	{
 		printf("\t%d\t%d \t",stu[i].grade ,stu[i].score );
 		for(j=0;j<stu[i].score ;j++)
 		{
 			printf("*");
		 }
		 printf("\n");
	 }
 	
 }
 //8.8 餐饮打分并输出结果
//8.9众数,中位数,平均数
#include<stdio.h>
#define MAX 40 
struct STU
{
	int grade;
	int score;
	
 }stu[MAX];
 void printbasis(struct STU a[],int n);
 int Ave_Mid_Mod(struct STU a[],int n);
int main()
{
	int i,n;
	printf("please Enter the total number of students:");
	scanf("%d",&n);
	printf("please Enter the student's score(separated by spaces):");
	for(i=0;i<n;i++)
	{
		stu[i].grade = i+1;
		scanf("%d",&stu[i].score); 
	 }
	 
	printbasis(stu,n);
	Ave_Mid_Mod(stu,n);
	return 0;
 } 
 
 void printbasis(struct STU a[],int n)
 {
 	int i,j;
 	printf("\tGRADE \tCOUNT \tHISTOGRAM\n");
 	for(i=0;i<n;i++)
 	{
 		printf("\t%d\t%d \t",a[i].grade ,a[i].score );
 		for(j=0;j<a[i].score ;j++)
 		{
 			printf("*");
		 }
		 printf("\n");
	 }
 	
 }
 
 int Ave_Mid_Mod(struct STU a[],int n)
 {
 	float ave,sum=0;
 	float mid;
 	float mod=0;
 	int i;
 	
 	for(i=0;i<n;i++)
 	{
 		sum += (float)a[i].score;
 		
	 }
 	printf("平均值:%.3f",(float)sum/n);
 	/*************************/
 	if(n%2==0)
 	{
 		mid =(float) a[n/2].score+a[(n-1)/2].score;
 		mid /= 2;
	 }
	 else
	 {
	 	mid =(float) a[n/2].score;
	 }
	 printf("中间值:%.3f",mid);
	 /*****************************/
	 int count[10]={0};
	 int k=0;
	 for(i=0;i<n;i++)
	 {
	 	count[a[i].score]++; 
	 } 
	 for(i=0;i<10;i++)
	 {
	 	if(k<count[i])
	 	{
	 		k=count[i];
	 		mod=i;
		 }
	 }
	 
 	printf("众数:%.0f",mod);
 }
 //8.10 矩阵对角线元素和
 #include<stdio.h>
#define MAX 100
int main()
{
	int n,i,j;
	int number[MAX][MAX]={0};
	printf("Please enter the size of the matrix:\n");
	scanf("%d",&n);
	printf("Please enter each element of the matrix by row:\n");
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			scanf("%d",&number[i][j]);
		}
	}
	int sum = 0;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(i==j)
			{
				sum += number[i][j] + number[n-1-i][n-1-j];
			}
		}
		
	}
	if(	n%2== 1)
	{
		sum -= number[n/2][n/2];
	}
	
	printf("对角的线性和:%d",sum);
	
	return 0;
}
//8.10计算两个矩阵的和
#include<stdio.h>
#define MAX 100
void Input_basis(int,int n,int a[MAX][MAX]);
int main()
{
	int m,n,i,j;
	int number_a[MAX][MAX]={0};
	int number_b[MAX][MAX]={0};

	
	printf("Please enter the size of the row and column:\n");
	scanf("%d%d",&m,&n);	
	
	 Input_basis(m,n,number_a);	
	 Input_basis(m,n,number_b);	
	
	int sum = 0;
	for(i=0;i<m;i++)
	{
		for(j=0;j<n;j++)
		{
			sum = number_a[i][j] + number_b[i][j];
			printf("%d ",sum); 
		}
		printf("\n");
	}
	
	return 0;
}
void Input_basis(int m,int n,int a[MAX][MAX])
{
	printf("Please enter the number:\n");
	int i,j;
	for(i=0;i<m;i++)
	{
		printf("input the row:%d\n",i+1);
		for(j=0;j<n;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
}
//打印杨辉三角(下三角)
#include<stdio.h>
#define MAX 7
int main()
{
	int i,j;
	int a[MAX][MAX]={0};
	
	for(i=0;i<MAX;i++)
	{
		for(j=0;j<MAX;j++)
		{
			if(i==j)
			{
				a[i][j]=1;
				break;
			}
			else if(j==0)
			{
				a[i][j]= 1;
			}
			else
			{
				a[i][j] = a[i-1][j-1]+a[i-1][j];
			}
		}
	}
	
	for(i=0;i<MAX;i++)
	{
		for(j=0;j<MAX;j++)
		{
			printf("%d\t",a[i][j]);
			if(i==j)
			{
				printf("\n");
				break;
			}
		}
		
	}


	return 0; 
} 
//8.14模拟6000次筛子投掷
#include<stdio.h>
#include<stdlib.h>
#include<time.h> 
#define COUNTS 6000
int main()
{
	int temp,i;
	int number[6]={0};
	
	srand(time(NULL));
	for(i=0;i<COUNTS;i++)
	{
		temp = rand()%6+1;
		//printf("%d\n",temp);
		number[temp-1]++;
	}
	printf("The probability of occurrence is respectively\n");
	for(i=0;i<6;i++)
	{
		printf("%d : %f\n",i+1,(float)number[i]/COUNTS);
	}
	
	
	
	return 0;
 } 
//8.15 猜数字
#include<stdio.h>
#include<math.h> 
#include<time.h>
#include<stdlib.h>
void Base_page_print();
int Inequality_yes_no( int *a);
int *Split(int a,int *b); 
int Basis_number();
int Judge_A(int *user,int *computer);
int Judge_B(int *user,int *computer);
int c_number[4];

int main()
{
 	int users_number;
    int u_number[4]; 	
 	int count_A=0,count_B=0;
	int time=1;
	char ch;
	
	FILE *fp;
	fp =  freopen("rxy.txt","r",stdout);
	
	while ((ch=fgetc(fp))!=EOF)
    printf("%c", ch);
    fclose(fp);	
     
    freopen( "CON", "w", stdout );
		
	Basis_number();
//	Base_page_print();
	
	printf("Please enter the number of times you want to guess ( ̄︶ ̄)↗:\n");
 	scanf("%d",&time);
 	do
	{
		
 		printf("Please enter your number o(* ̄▽ ̄*)o:\n");
    	scanf("%d",&users_number);
 	    
 		
 		Split(users_number,u_number); 
 		count_A = Judge_A(u_number,c_number);
	    count_B = Judge_B(u_number,c_number);
	
     	printf("%dA %dB\n",count_A,count_B);
     	if(count_A == 4)
     	{
     		printf("Congratulations!(〃 ̄︶ ̄)人( ̄︶ ̄〃)\n");
     		break; 
		 }
 		time--;
	 }while(time);
 	
 	 if(time <= 0)
 	 {
 	 	printf("Sorry,you haven't guess the right number!ヾ( ̄▽ ̄)Bye~Bye~\n"); 
	  }
    
 	
 	/*
 	for(int i=0;i<4;i++)
 	{
 		printf("%d",*(c_number+i));
	 }
	 printf("\n******\n");
	 for(int i=0;i<4;i++)
 	{
 		printf("%d",*(u_number+i));
	 }
 	*/
 	return 0;
}

int Judge_B(int *user,int *computer) 
{
	int count = 0;
	for(int i=0;i<4;i++)
	{
		for(int j=0;j<4;j++)
		{
			if(*(user+i)==*(computer+j))
			{
				if(i != j)
				{
					count++;
				 } 
			}
		}
	}
	
	return count;
}

int Judge_A(int *user,int *computer)
{
	int count=0;
	for(int i=0;i<4;i++)
	{
		if(*(user+i)== *(computer+i))
		{
			count++;
		//	printf("%d %d\n",*(user+i),*(computer+i));
		}
	}
	return count;
}
//判断数字对位置对
int* Split(int a,int *b)
{
	int i=3;
//	printf("welcome to split!\n");
	for( ;i>= 0;i--)
	{
		b[i] = a % 10;
		a /= 10; 
	  //  printf("%d\n",b[i]);
	
	}
	
	return b;
}
 //完成拆分
 int Inequality_yes_no( int *a)
{
//	printf("welcome to equality!\n");
	int i,j,flag = 0;
	for(i=0;i<4;i++)
	{
		for(j=i+1;j<4;j++)
		{
	//		printf("%d %d\n",a[i],a[j]);
			if(a[i]==a[j])
			{
				flag = 1;
				goto stop;
			}
		}
	}
	
	stop: return flag;
}
//判断是否互异 1代表互异 

int Basis_number()
{
	srand(time(NULL));
	int temp,flag = 1;
	
	do
	{	
		temp = rand()%9000+1000;
	
		flag=Inequality_yes_no(Split(temp,c_number));			
		
	}while(flag); 
	
	printf("the right answer to the Guess Number Game:%d\n",temp);
	
	return temp;
}
//生成一个四位互异的数 
void Base_page_print()
{
printf(".......................................................................................................................................................................................................................................................................................\n"); 
printf(".......................................................................................................................................................................................................................................................................................\n");
printf(".......................................................................................................................................................................................................................................................................................\n");
printf("............................................................................................................ ..........................................................................................................................................................................\n");
printf(".......................................................................................................................................................................................................................................................................................\n");
printf(".................................................................................................................]]OOO]][email protected]@@@@@@@@@@@@@@@@@OOO\]]]...................................................................................................................................\n");
printf("............................................................................................]/[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O]`............................................................................................................................\n");
printf("....................................................................................,]/@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O]..................................................... ..................................................................\n");
printf("...............................................................................,]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@]....................................................................................................................\n");
printf("............................................................  .... ........]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\......................        ..................,]....    .......................................................\n");
printf("......................................................................,/@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\[email protected]^...............................................................\n");
printf("..................................................................,/@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\`..]]]`...[email protected]/................................................................\n");
printf("...............................................................][email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\..]]]]]]]]].......................................................................................\n");
printf("............................................................/@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@O].......  .......................................................................\n");
printf(".........................................................]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@`................................................. ...........................\n");
printf("......................................................,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@\..........,[email protected].\n");
printf("............................................ ......,/@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@^.........,[[email protected]@.......]/@@@@@@\...... .......................\n");
printf("................................................./@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@@@[email protected]@@^[email protected]@....,[email protected]@@@@@@@@O`.............................\n");
printf("..............................................,/@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O\`\[email protected]@@@[email protected]@@^[email protected]@[email protected]@@@@@O[`.................................\n");
printf("............................................,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^,/\/\[email protected]@@@[email protected]@@@^[email protected]@^....\O[.......................................\n");
printf(".................................... .....]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/oOO/[\o\@@@@@@[email protected]@@[email protected]@^....... ......................................\n");
printf("........................................,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O/,[email protected]@@@@@@[email protected]@@@@`[email protected]@^..............................................\n");
printf("[email protected]@@@@O/\*[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@O`[email protected]@@...........,]/[email protected]@@/...........................\n");
printf("[email protected]@@@@@o\/\[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O\@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@^[email protected]@^....,@@@@@@@@@@/`............................\n");
printf("..................................../@@@@@O\o,[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@\[email protected]@@.....[[email protected]/[................................\n");
printf("[email protected]@@@@O\\/o\/@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@O\o\o/\/[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@\[email protected]@\.......  ...................................\n");
printf("....................,]]..........,@@@@@@@\o^[email protected]@@@O\/[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@O/\@@@@@@@@@@@@@@@@O^[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\.......................[O^......   ...        .......................\n");
printf("................./@@[email protected]\.......,@@@@@@@@\/[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O`[email protected]@@@@@@@@@@@@\=\[email protected]@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@^...........................  ..              .......................\n");
printf("..............]@@[email protected]^[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O,/[email protected]@@@@@@@@@@@@@\o/@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^......................  ......              .......................\n");
printf("............/@OOOOOOOOOOO\[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`..................................................................\n");
printf("........../@[email protected][email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.............................../[email protected]@@@@@^..........................\n");
printf("........,@[email protected]@@@@O][email protected]@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^\@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\.................... .....,/@@@@@@@@@@O..........................\n");
printf("......./@[email protected]@@[email protected]@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^*,[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@@@@@@O/[[`...........................\n");
printf(".....,@@[email protected]@[email protected]@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O.**,[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.................. [email protected]@@@@/...................................\n");
printf("[email protected]@[email protected]@@[email protected]@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\/@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^...**[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@@O`.....................................\n");
printf("[email protected]@[email protected]@@@@[email protected]@[email protected]@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.....................,/`.......................................\n");
printf("....,@@@@@@@@@@@@@@@@@[email protected]@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/[[/[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\........,\@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^..............................................................\n");
printf(".............,[email protected]@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/\*.`**[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^..........,[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..............................................................\n");
printf(".........../@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O`...*,,[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O.............,[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^......................  .....][email protected]@@...........................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^.....**`[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^...............,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.......................]]]/@@@@@@^...........................\n");
printf("......../@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O.......,`,[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O..................[@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@@@@@@@@O`............................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^........,`,[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`....................\@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O....................,[email protected]@@@@O[...............................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^...........,/[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^......................,\@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^...........................................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/.............=*[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@^.........................\@@@@@@@@@^[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...........................................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O...............,*[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/@@@@@@@@@@@@@@^...............]]]]]]`.....,@@@@@@@@.,[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^..........................................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O.................**\@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@^.........../@@@@@@@@@@@@@@@O\[email protected]@@@@@\[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O..........................................................\n");
printf("....,@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O`...................*[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@@@@@@@@@@@^........,[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@^...\@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^.........................................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O`.....................,/[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@O,[email protected]@@@@@@@@@@^......,@@@O/[[`......[[[email protected]@@@@@@@@@@@@@`[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@O............................,............................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O`........................*[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@@@@@@@@@@^....,OO`...................,[email protected]@@@@@@@@@`....,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^........................../@`...........................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O*........]/[email protected]@@@@@@@@@@@@@O\\@@@@@@@@@@@@@@@@@@@@@@@@@@O*[email protected]@@@@@@@@@^.............]/@@@@@@@\]......,@@@@@@@@@\.....\@@@@@@@@@@@@@@@@@@@@@@@@@@@@........................./@/............................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O.....,/@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@@@@@@@@@...........,@@@@@@@[email protected]@@@O`....,@@@@@@@@@`....,@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@`............................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/...]@@@@@@@@@@@@@@@OO[[[[[[[[email protected]@@O/@@@@@@@@@@@@@@@@@@@@@@@@O*[email protected]@@@@@@@@.........,@@@@[email protected]@@\....\@@@@@@@@.....,@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@.............................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^../@@@@@@@@@@O[.... ...............`[email protected]@@@@@@@@@@@@@@@@@@@@@@^[email protected]@@@@@@@/..........[[[[email protected]@[email protected]@@`[email protected]@@@@@\[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@^......................,[email protected]@@]..........................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`./@@@@@@@@@/.......,]]OOO]]`.........*,[email protected]@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@`........].....\@[email protected]@^[email protected]@@@@@`[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@.........................[@@@\........................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/[email protected]@@@@@@@O`.....][email protected]@@[email protected]@@@@O`.......*[email protected]@@@@@@@@@@@@@@@@@@@@^[email protected]@@@@@^[email protected]/@[email protected]@^....,@@@@@^[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@\..........................,@@\.......................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/./@@@@@@@@`......,@@@[email protected]@@\.......,\@@@@@@@@@@@@@@@@@@@@`[email protected]@@@@[email protected]@@@@@@[email protected][email protected]@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@^.........................,@@/.......................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@@@@@@/[email protected]@[email protected]@O........,\@@@@@@@@@@@@@@@@@@[email protected]@@@`[email protected]@[email protected]@^[email protected]@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@/........................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`./@@@@@@@`.....,O`[email protected]@@`........,[email protected]@@@@@@@@@@@@@@@@^\@@`[email protected]@@@[email protected][email protected]@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@^........................`..........................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`[email protected]@@@@@@`...../@@@@[email protected]@@^.........,[email protected]@@@@@@@@@@@@@@@`[email protected]@@@[email protected]@@[email protected]@[email protected]@@^[email protected]@@@@@@@@@@@@@@@@@@@@@@@@O\@@@^..................................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\..,@@@@@@@`...../@@[email protected]@[email protected]@^...........\@@@@@@@@@@@@@@@`[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]^[email protected]^[email protected]@@@@@@@@@@@@@@@@@@@@@@@O`[email protected]@@..................................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`./@@@@@@^[email protected]@[email protected]@@[email protected]@`............\@@@@@@@@@@@@@O`[email protected]@[email protected]@[email protected]@@@@@[email protected]@[email protected]@^......./[email protected]@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@\.................................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\,@@@@@@/[email protected]@[email protected]@[email protected]@O..............\@@@@@@@@@@@@O..........\@@[email protected]@@[email protected]@O.................\@@@@@@@^[email protected]@@@@@@@@@@@@@@@@@@@@^... .    .......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/@@@@@[email protected]@[email protected]@@@[email protected]@[email protected][email protected]@@@@@@@@@@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@@@@@@^\[email protected]@@@@O\@@@@@@@@@@@@@`....    .......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`[email protected]@@@[email protected]@[email protected]@@O..................,[email protected]@@@@@@@@\..........\@@@[email protected]@@@@[email protected]@@[email protected]@@`[email protected]@@@@@O//o\\[email protected]@@@@@@@@@@@@@@@@O......  .......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@[email protected]@[email protected]@[email protected]@@@@@@[email protected]@@^.....................\@@@@@@@@^...........[@@@@[email protected]@[email protected]@@/`......,^...............\@@@@@@O^\@@@@@@@@@@@@@@@@@@@@@^.....  .......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..........\@[email protected]@[email protected]@@........................,[email protected]@@@@@^.............,\[email protected]@@@@@@@@O[.........,O....,[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^.............................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@[email protected]@@`...........................\@@@@@^\`................................,O....O^....`[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.............................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@............\@@[email protected]@[email protected]@@@^...............................\@@@`............................=/[email protected]^...O^....O`.\......\@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\............................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@.............,[email protected]@[email protected]@@[email protected]@[email protected]@@@`..................................,\@@].........................,@...O/..,@^...,O`,@`[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^...........................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............,\@@@@[email protected]@[email protected]@@/........................................,`[email protected]^../\/..,@^...,@`[email protected]`[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`..........................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..............,....,\[email protected]@@@@@@@@@@O`...................................................................=O../@..,@/[email protected]`[email protected]^[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..........................................\n");
printf("............,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^............=^..................../..................................................................\[email protected]^[email protected][email protected]`.,`[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O.........................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`........../^...=^..........`...,O.......[email protected]^[email protected][email protected]`[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\... ....................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O.........O`.../\/....../^.,/...=/..............................................................,/^.....=/[email protected]`[email protected]`[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@\.......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\......,@`.../\/.....,@^./O.../^...................................]/[email protected]@@@@@@@@OO]]]]]`..]]][email protected]@O`[email protected]`[email protected][email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@\......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`[email protected]`.../O.....,@^./O..,O`........`......................,/[email protected][\]]]]]]]]/[[[email protected]`.........,`...[[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@^.,@@^.....................................\n");
printf("[email protected]@@/`\@@[email protected]@@@@@@@@@@@@@@@@@@@@/[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@..../[email protected]^[email protected]`..........=O\`...........]][email protected]/[^,o/oooooooo[[oooo][email protected]/@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\[email protected]@\....................................\n");
printf("[email protected]@@O\/[email protected]@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@\......../[email protected]^.OO../\/...........,O=/`O.\OOOOO[[^*oooooooooooooooooooooooooooooo\[email protected]^[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@....\@O...................................\n");
printf("[email protected]@@/^[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@O,[email protected]@^............/@`.OO.,@/...........,O\[/\\OO\=^oooooo^[email protected]^[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^....,@@^.................................\n");
printf("[email protected]@@@^[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@[email protected]/@@@`[email protected]`./\/\.,@^............OO=ooooooooooooooooooooooooooooooooooooooooooooooooo\o^[email protected]^................................/@@/[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@O......,@\................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/o\@@@@@@@@@@@@@@@@@@O.........,/...`..O`............,@^==oooooooooooooooooooooooooooooooooooooooooooooooooooo,[email protected]^..............................,@@@/...\@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@`[email protected]`...... .......................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\@@@@O/o\[email protected]@@@@@@@@@@@@@@@@\...............[..............=O==ooooooooooooooooooooooooooooooooooooooooooooooooooooo\[email protected]/@@@`[email protected]@@@@@/@@@@@@@@@@@@@@@@@@@^...............  .......................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^,@@@@@o^[email protected]@@@@@@@@@@@@@@@@@^.............................=O=oooooooooooooooooooooooooooooooooooooooooooooooooooooo,O^............................]@@@/........,[email protected]@@@@`\@@@@@@@@@@@@@@@@@O...............  .......................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@@@@@@@@@@@@@@@@@@@@@@@@`............................=O==ooooooooooooooooooooooooooooooooooooooooooooooooo^o/\/[email protected],@@@[email protected]@@@@^\@@@@@@@@@@@@@@@@@........................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...,@@@@@@@@@@@@@@@@@@@@@@@@@............................=O^==ooooooooooooooooooooooooooooooooooooooooooooooooo^[oO........................../@@@O`...............\@@@@[email protected]@@@@@@@@@@@@@@@^.......................................\n");
printf("...................\@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^...,@@@@@@@@@@@@@@@@@@@@@@@@[email protected]^==oooooooooooooooooooooooooooooooooooooooooooooooooo\@........................,/@@@/....................[@@@@,@@@@@@@@@@@@@@@^.......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\....,@@@@@@@@@@@@@@@@@@@@@@@@^...........................\O,\oooooooooooooooooooooooooooooooooooooooooooooooo,\@.......................,@@@@/..... ..................,@@@/@@@@@@@@@@@@@@^.......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`....,@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]\/ooooooooooooooooooooooooooooooooooooooooooo/\o^OO.....................,[email protected]@@@`............................,[email protected]^@@@@@@@@@@@@@^.......................................\n");
printf("....................\@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^.....,@@@@@@@@@@@@@@@@@@@@@@@@`[email protected]^=^ooooooooooooooooooooooooooooooooooooooooo^o,O`...................]@@@@@`..................................\\@@@@@@@@@@@@O.......................................\n");
printf("....................,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@`...........................\@O`/\/o]ooooooooooooooooooooooooooooo\ooo\o^\oO^.................,/@@@@O`[email protected]@@@@@@@@@@O.......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^.......\@@@@@@@@@@@@@@@@@@@@@@@............................,@O^=^o/oooooooooooooooooooooooooooo/oo]\/O/`...............,/@@@@@/`[email protected]@@@@@@@@@@.......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@@@@@@@@@@@@@@@@@@@@@O.............................\@Oo\\\]/o[\oooooooooooooooooooo\/]/oOO`...............]@@@@@O[................................................,@@@@@@@@@@.......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@\..............................[@@OOoo/\/o/oooooooooooo]/o/\*]/[email protected]/`..............]@@@@@@[.....................................................,@@@@@@@@@.......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@@@@@@@@@@@@@@@@@@@@\................................,[[email protected]@@OOO\]/]]]]]]][email protected]@@@/`.............,/@@@@@@/[email protected]@@@@@@@.......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@O\].................................,[[[O/OOO/[[[................,][email protected]@@@@@/`[email protected]@@@@@O.......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`[email protected]@@@@@@@@@@@@@@@@@@@\.[\@@@@@O\]]................................................]][email protected]@@@@@@/[...................................................................,@@@@@@O.......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\..............\@@@@@@@@@@@@@@@@@@@\......[\@@@@@@@@@O\]]]].............................]/@@@@@@@@@@/[...........[email protected]@@@@^.......................................\n");
printf("[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...............,@@@@@@@@@@@@@@@@@@@@............[[\@@@@@@@@@@@@O`****.............***][email protected]@@@O[[...................[email protected]@@@^.......................................\n");
printf("[email protected]@@@^[email protected]@@@@@@@@@@@@@@@@@@@@/@@@@@@@^................,@@@[email protected]@@@@@@@@@@@@@`.....................,@O`*,^******************=*`[email protected]^........................[email protected]@@^.......................................\n");
printf("[email protected]@@@^,@@@@@@@@@@@@@@@@@@@@@^,@@@@@@@[email protected]@^[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@O].,.]@@@@@\\=^******************,[email protected]/\/].......................[email protected]@@........................................\n");
printf("[email protected]@@@^[email protected]@@@@@@@@@@@@@@@@@@@O.,@@@@@@^[email protected]^.\@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[@@/..,@@\*******************,[email protected]@^.\@O^.`.................................................................................[@^........................................\n");
printf("[email protected]@@^[email protected]@@@@@@@@@@@@@@@@@@@[email protected]@@@@@....................\@\]/@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@^[email protected]@^,\************``*\@@^[email protected]@@@@@@@@@@@@]`................................................................... [email protected]\n");
printf("[email protected]@@`...,@@@@@@@@@@@@@@@@@@@^[email protected]@@@@^[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@.....\@@\***************[email protected]@^.../@^[email protected]@@@@@@@@@@@@@@`...................................................................=^.........................................\n");
printf("[email protected]@@.....,@@@@@@@@@@@@@@@@@@[email protected]@@@@`................,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]\@@]`,,********\[email protected]@/[email protected]@^[email protected]@@@@@@@@@@@@@@@@\............................................................................................................\n");
printf("[email protected]@^[email protected]@@@@@@@@@@@@@@@@[email protected]@@O...............\/@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@\......,@@O`,*******,,@@/[email protected]@.,@@@@@@@@@@@@@@@@@@@`...... ...................................................................................................\n");
printf("[email protected]\@@@@@@@@@@@@@@@@^......\@@\............./@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@^[email protected]@^[email protected]@^,,*`,,=,@@[email protected]^[email protected]@@@@@@@@@@@@@@@@@@@^.........................................................................................................\n");
printf("[email protected]`[email protected]@@@@@@@@@@@@@@@........\@\...........\/@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]\[email protected]@\`,,\,*[email protected]@`[email protected]@^[email protected]@@@@@@@@@@@@@@@@@@@.........................................................................................................\n");
printf("......................../^[email protected]@@@@@@@@@@@@@^.........,O`[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`/[email protected]@@@@OO]]]..,[email protected]@][*^/@@^[email protected]@[email protected]@@@@@@@@@@@@@@@@@@\........................................................................................................\n");
printf("........................O...............,@@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@[email protected]@@@@@@@@@O\`[email protected]@.,][email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`.......................................................................................................\n");
printf("..........................................,@@@@@@@@@@@@\[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OOOOOOO[email protected]@[email protected]@@@@@@@@@[email protected]@[email protected]@@@@@@@@@@@@@@@@@@@@@@@^.......................................................................................................\n");
printf("............................................,[email protected]@@@@@@@@@^[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[email protected]@@[email protected]@[email protected]@@@[email protected]@@@[email protected]@[email protected]@[email protected]@[email protected]@@@@@@@@@@@@@@@@@@@@/.......................................................................................................\n");
}

 

 

 


转载自blog.csdn.net/qq_42580577/article/details/88087681'作为字符串的结束 */ //printf("%d\n",sizeof(pStr));//字符指针的大小 //printf("%d\n",sizeof(ch));//输出的一定是5:数组的大小 int num = sizeof(pArray)/sizeof(void*); // printf("%d",sizeof(void*)); printf("Total string numbers = %d \n",num); Print(pArray,num); return 0; } void Print(const char *arr[],int len) { int i; for(i=0;i<len;i++) { printf("%s ",arr[i]); //printf("%d",i); } printf("\n"); } //11.2 (2) #include<stdio.h> void InputArray (int *pa,int n); void OutputArray(int *pa,int n); int main() { int a[5]; printf("Input five numbers:\n"); InputArray(a,5); OutputArray(a,5); return 0; } void InputArray(int *pa,int n) { /* for(;pa<pa+n;++pa) { scanf("%d",pa); } pa与pa+n同时增加一 */ for(int i = 0 ;i<n;++i) { scanf("%d",pa+i); } } void OutputArray(int *pa,int n) { for(int i=0;i<n;++i) { printf("%4d",*pa+i); } printf("\n"); } //11.2(3)输入n门课程计算总分平均分 /* 一维指针即使里面放的是地址,也不能用二维的方式进行操作 https://bbs.csdn.net/topics/370086928 */ #include<stdio.h> #define STUD 30 #define COURSE 5 void Total(int *score,int sum[],float aver[],int m,int n); void Print(int *score,int sum[],float aver[],int m,int n); int main() { int i,j,m,n,score[STUD][COURSE],sum[STUD]; float aver[STUD]; printf("How many students?"); scanf("%d",&m); printf("How many courses?"); scanf("%d",&n); printf("Input score:\n"); for(i =0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&score[i][j]); } } /* for(i =0;i<m;i++) { for(j=0;j<5;j++) { printf("%d ", score[i][j]); printf("=%d ", &score[i][j]); } printf("\n"); }*/ // printf("*score=%d\n",**score); Total(*score,sum,aver,m,n); Print(*score,sum,aver,m,n); return 0; } void Total(int *pScore,int sum[],float aver[],int m,int n) { int i,j; for(i=0;i<m;i++) { sum[i]=0; for(j=0;j<n;j++) { sum[i] = sum [i]+pScore[i*COURSE+j]; // printf("pScore[i*n+j]=%d\n",pScore[i*COURSE+j]);//行指针未赋值 } aver[i] = (float)sum[i]/n; } } void Print(int *pScore,int sum[],float aver[],int m,int n) { int i,j; printf("Result:\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%4d\t",pScore[i*COURSE+j]); } printf("%5d\t%6.llf\n",sum[i],aver[i]); } } //11.4输出矩阵转置nXn #include<stdio.h> #include<stdlib.h> #define N 20 void tran_spose1(int a[][N],int n); void tran_spose2(int (*a)[N],int n); void tran_spose3(int *a,int n); int main() { int n; int i,j; int number[N][N]={0}; printf("please enter the scale of your matrix:"); scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf("%d",&number[i][j]); //printf("%d ",number[i][j]); } } tran_spose3(*number,n); for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d ",number[i][j]); } printf("\n"); } } void tran_spose3(int *a,int n) { int swap = 0; int *flag =NULL; flag = (int *)calloc(n*n,sizeof(int)); if(flag==NULL) { printf("no enough room"); exit(1); } for(int i=0;i<n;i++) { for(int j =0;j<n;j++) { if((i!=j)&&(flag[i*n+j]==0)) { flag[i*n+j]=1; flag[j*n+i]=1; swap = a[i*N+j]; a[i*N+j]=a[j*N+i]; a[j*N+i]= swap; } } } free(flag); } void tran_spose2(int(*a)[N],int n) { int swap = 0; int *flag =NULL; flag = (int *)calloc(n*n,sizeof(int)); if(flag==NULL) { printf("no enough room"); exit(1); } for(int i=0;i<n;i++) { for(int j =0;j<n;j++) { if((i!=j)&&(flag[i*n+j]==0)) { flag[i*n+j]=1; flag[j*n+i]=1; swap = *(a+i)[j]; *(a+i)[j]=*(a+j)[i]; *(a+j)[i] = swap; } } } free(flag); } void tran_spose1(int a[][N],int n) { int swap = 0; int *flag =NULL; flag = (int *)calloc(n*n,sizeof(int)); if(flag==NULL) { printf("no enough room"); exit(1); } for(int i=0;i<n;i++) { for(int j =0;j<n;j++) { if((i!=j)&&(flag[i*n+j]==0)) { flag[i*n+j]=1; flag[j*n+i]=1; swap = a[i][j]; a[i][j]=a[j][i]; a[j][i] = swap; } } } free(flag); } //11.4输出矩阵转置nXm #include<stdio.h> #include<stdlib.h> #define N 20 void tran_spose1(int a[][N],int n,int m); void tran_spose2(int (*a)[N],int n,int m); void tran_spose3(int *a,int n,int m); int main() { int n,m; int i,j; int number[N][N]={0}; printf("please enter the scale of your matrix(nXm):"); scanf("%d",&n); scanf("%d",&m); for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%d",&number[i][j]); //printf("%d ",number[i][j]); } } tran_spose2(number,n,m); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d ",number[i][j]); } printf("\n"); } } void tran_spose3(int *a,int n,int m) { int swap = 0; int *flag =NULL; int max; max = n>m ? n:m; flag = (int *)calloc(max*max,sizeof(int)); if(flag==NULL) { printf("no enough room"); exit(1); } for(int i=0;i<max;i++) { for(int j =0;j<max;j++) { if((i!=j)&&(flag[i*max+j]==0)) { flag[i*max+j]=1; flag[j*max+i]=1; swap = a[i*N+j]; a[i*N+j]=a[j*N+i]; a[j*N+i]= swap; } } } free(flag); } void tran_spose2(int(*a)[N],int n,int m) { int swap = 0; int *flag =NULL; int max; max = n>m ? n:m; flag = (int *)calloc(max*max,sizeof(int)); if(flag==NULL) { printf("no enough room"); exit(1); } for(int i=0;i<max;i++) { for(int j =0;j<max;j++) { if((i!=j)&&(flag[i*max+j]==0)) { printf("(。^▽^)\n"); flag[i*max+j]=1; flag[j*max+i]=1; swap = *(a+i)[j]; *(a+i)[j]=*(a+j)[i]; *(a+j)[i] = swap; } } } free(flag); } void tran_spose1(int a[][N],int n,int m) { int swap = 0; int *flag =NULL; int max; max = n>m ? n:m; flag = (int *)calloc(max*max,sizeof(int)); if(flag==NULL) { printf("no enough room"); exit(1); } for(int i=0;i<max;i++) { for(int j =0;j<max;j++) { if((i!=j)&&(flag[i*max+j]==0)) { flag[i*max+j]=1; flag[j*max+i]=1; swap = a[i][j]; a[i][j]=a[j][i]; a[j][i] = swap; } } } free(flag); } //习题11 //11.1 #include<stdio.h



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: