设为首页 加入收藏

TOP

C语言指针(二)
2012-11-05 11:36:20 来源: 作者: 【 】 浏览:578
Tags:语言 指针

 

  for(pass=1;pass<size;pass++)

  for(count=0;count<size-pass;count++)

  {

  if((*compare)(work[count],work[count+1]))

  swap(&work[count],&work[count+1]);

  }

  }

  int main()

  {

  int order;

  int counter;

  int a[SIZE]={2,6,4,8,10,12,89,68,45,37};

  printf("\nData items in original order:\n");

  for(counter=0;counter<SIZE;counter++)

  printf("%5d",a[counter]);

  printf("\nEnter 1 to sort in accending order,\n"

  "Enter 2 to sort in descending order: ");

  scanf("%d",&order);

  if(order==1)

  {

  bubble(a,SIZE,ascending);

  printf("\nData items in ascending order:\n");

  }

  else

  {

  bubble(a,SIZE,descending);

  printf("\nData items in descending order:\n");

  }

  for(counter=0;counter<SIZE;counter++)

  printf("%5d",a[counter]);

  printf("\n");

  return 0;

  }

  (2) 函数指针数组

  [cpp]

  #include<stdio.h>

  void function1(int a);

  void function2(int a);

  void function3(int a);

  int main()

  {

  void (*f )(int)={function1,function2,function3};

  int choice;

  printf("Enter a number between 0 and 2, 3 to end: ");

  scanf("%d",&choice);

  while(choice >=0 && choice<3)

  {

  (*f[choice])(choice);

  printf("Enter a number between 0 and 2, 3 to end: ");

  scanf("%d",&choice);

  }

  printf("Program execution completed.\n");

  return 0;

  }

  void function1(int a)

  {

  printf("You entered %d so funtion1 was called\n\n",a);

  }

  void function2(int a)

  {

  printf("You entered %d so funtion2 was called\n\n",a);

  }

  void function3(int a)

  {

  printf("You entered %d so funtion3 was called\n\n",a);

  }

      

首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C语言数组应用 下一篇C语言指针和数组概述

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: