59

59 date:2021.3.8
在这里插入图片描述

要点:
读源码

要使用函数对整个数组进行操作,应使用数组名作为函数的实参。当使用数组名作实参时,函数传递
的实际上是数组的首地址,而非数组本身; 此时,形参除了可以定义为指针变量外,还可以定义为数组,并且数组可以不指定大小; 综上,不论用哪种形式,程序在编译时都将其作为一个指针变量处理

详细代码如下:

#include    <stdio.h>
typedef  struct
{  int  num;
   char  name[10];
}PERSON;
/**********found**********/
void fun(PERSON  std[])
{
/**********found**********/
    PERSON temp;
   if(std[0].num>std[1].num)
  {  temp=std[0];  std[0]=std[1];  std[1]=temp;  }
   if(std[0].num>std[2].num)
  {  temp=std[0];  std[0]=std[2];  std[2]=temp; }
   if(std[1].num>std[2].num)
  {  temp=std[1];  std[1]=std[2];  std[2]=temp;  }
}
void main()
{  PERSON  std[ ]={ 5,"Zhanghu",2,"WangLi",6,"LinMin" };
   int  i;
/**********found**********/
   fun( std);
   printf("\nThe result is :\n");
   for(i=0; i<3; i++)
      printf("%d,%s\n",std[i].num,std[i].name);
}

在这里插入图片描述

要点:

详细代码如下:

#include <stdio.h>
#include <string.h>
void  fun ( char  str[][10], int  m, char  *pt )
{
/************found************/
    int  k, q, i ;
    for ( k = 0; k < m; k++ )
    {  q = strlen ( str [k] );
       for (i=0; i<q; i++)
/************found************/
       pt[i] = str[k][i] ;  //二维数组表示为str[k][i]
       pt += q ;
       pt[0] = 0 ;
    }
}

void main( )
{    int  m, h ;
     char s[10][10], p[120] ;
     printf( "\nPlease enter  m:" ) ;
     scanf("%d", &m) ;  gets(s[0]) ;
     printf( "\nPlease enter  %d string:\n", m ) ;
     for ( h = 0; h < m; h++ ) gets( s[h]) ;
     fun(s, m, p) ;
     printf( "\nThe result  is :  %s\n", p) ;
}


在这里插入图片描述
要点:
左下半三角形
右上半三角形
主对角线(右)
次对角线(左)

详细代码如下:

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#define N 5
void fun (int a[][N])
{
	/*
		analyse:

		遍历整个二维数组;

		左下半三角元素特征: 列小于等于行 j<=i;
			
	*/

	
	int i,j;
	for(i = 0; i<N; i++)
	{
		for(j = 0; j <= i; j++)
		{
			a[i][j]=0;
		}
	}
	
	

	//同理右上角三角形元素特征:列大于等于行 j>=i  不对!
	
	/*
	int i,j;
	for(i = 0; i<N; i++)
	{
		for(j = 0; j<= i; j++)
		{
			a[j][i]=0;  //  因为——> 这才是右上角 
		}
	}
	*/

	/*同理求两条对角线为0:

	
	//右对角线(主对角线)
	
	int i,j;
	for(i = 0; i<N; i++)
	{
		for(j = i; j == i; j++)
		{
			a[i][j]=0;
		}
	}
	

	//左对角线(次对角线) 
	
	??


	*/
	
}
void main()
{ 
  FILE *wf;
  int a[N][N],i,j;
  int b[N][N]={1,9,7,2,4,2,3,8,1,2,4,5,6,7,5,4,0,6,8,0,2,7,1,6,4};
  system("CLS");
  printf("*****The array*****\n");
  for(i=0;i<N;i++)              /*产生一个随机的5*5矩阵*/
     { for(j=0;j<N;j++)
          {a[i][j]=rand()%10; 
           printf("%4d", a[i][j]);
          }
       printf("\n");
     }
  fun(a);
  printf("THE RESULT\n");
  for(i=0;i<N;i++)
     { for(j=0;j<N;j++) 
          printf("%4d",a[i][j]);
       printf("\n");
     }
/******************************/
  wf=fopen("out.dat","w");
  fun(b);
  for(i=0;i<N;i++)
     { for(j=0;j<N;j++) 
          fprintf(wf,"%4d",b[i][j]);
       fprintf(wf,"\n");
     }
  fclose(wf);
/*****************************/
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值