结构体总结二

#include    <stdio.h>
typedef  struct
{  int  num;
   char  name[9];
   float  score[3];
}STU;
void show(STU  tt)
{  int  i;
   printf("%d  %s  :  ",tt.num,tt.name);
   for(i=0; i<3; i++)
     printf("%5.1f",tt.score[i]);
  printf("\n");
}
/**********found**********/
void modify(STU  *ss,float  a)//ss是指针结构体变量,前是STU
{  int  i;
   for(i=0; i<3; i++)
/**********found**********/
       ss->score[i]*=a;//分数乘以a
}
void main( )
{  STU  std={ 1,"Zhanghua",76.5,78.0,82.0 };
   float  a;
   printf("\nThe original number and name and scores :\n");
   show(std);
   printf("\nInput a number :   ");  scanf("%f",&a);
/**********found**********/
   modify(&std,a);//modify函数第一个变量是是指针结构体变量
   printf("\nA result of modifying :\n");
   show(std);
}

#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);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值