首页产品库评测行情新闻|手机数码笔记本台式机DIY硬件数字家庭数码相机办公外设|软件下载游戏开发|社区

更多

数码相机
MP4
LCD
机箱
音箱

天极网 > 开发频道>C语言程序开发经典实例之五

C语言程序开发经典实例之五

2004-06-19 15:25作者:出处:唯C世界责任编辑:方舟

  程序47】

  题目:宏#define命令练习(2)

  1.程序分析:            

  2.程序源代码:

#include "stdio.h"
#define exchange(a,b)
{
  /*宏定义中允许包含两道衣裳命令的情形,此时必须在最右边加上"\"*/
  int t;\
  t=a;\
  a=b;\
  b=t;\
}
void main(void)
{
 int x=10;
 int y=20;
 printf("x=%d; y=%d\n",x,y);
 exchange(x,y);
 printf("x=%d; y=%d\n",x,y);
}

  【程序48】

  题目:宏#define命令练习(3)   

  1.程序分析:

  2.程序源代码:

#define LAG >
#define SMA <
#define EQ ==
#include "stdio.h"
void main()
{
 int i=10;
 int j=20;
 if(i LAG j)
  printf("\40: %d larger than %d \n",i,j);
 else if(i EQ j)
  printf("\40: %d equal to %d \n",i,j);
 else if(i SMA j)
  printf("\40:%d smaller than %d \n",i,j);
 else
  printf("\40: No such value.\n");
}

  【程序49】

  题目:#if #ifdef和#ifndef的综合应用。

  1. 程序分析:

  2.程序源代码:

#include "stdio.h"
#define MAX
#define MAXIMUM(x,y) (x>y)?x:y
#define MINIMUM(x,y) (x>y)?y:x
void main()
{
 int a=10,b=20;
 #ifdef MAX
  printf("\40: The larger one is %d\n",MAXIMUM(a,b));
 #else
  printf("\40: The lower one is %d\n",MINIMUM(a,b));
 #endif
 #ifndef MIN
  printf("\40: The lower one is %d\n",MINIMUM(a,b));
 #else
  printf("\40: The larger one is %d\n",MAXIMUM(a,b));
 #endif
 #undef MAX
 #ifdef MAX
  printf("\40: The larger one is %d\n",MAXIMUM(a,b));
 #else
  printf("\40: The lower one is %d\n",MINIMUM(a,b));
 #endif
 #define MIN
 #ifndef MIN
  printf("\40: The lower one is %d\n",MINIMUM(a,b));
 #else
  printf("\40: The larger one is %d\n",MAXIMUM(a,b));
 #endif
}

  【程序50】

  题目:#include 的应用练习   

  1.程序分析:

  2.程序源代码:

  test.h 文件如下:
#define LAG >
#define SMA <
#define EQ ==
#include "test.h" /*一个新文件50.c,包含test.h*/
#include "stdio.h"
void main()
{
 int i=10;
 int j=20;
 if(i LAG j)
  printf("\40: %d larger than %d \n",i,j);
 else if(i EQ j)
  printf("\40: %d equal to %d \n",i,j);
 else if(i SMA j)
  printf("\40:%d smaller than %d \n",i,j);
 else
  printf("\40: No such value.\n");
}



共3页。 9 1 2 3

关注此文的读者还看过:

返回开发频道首页

共3页。 上一页123

软件频道最新更新

热点推荐

天极服务|关于我们|About us|网站律师|RSS订阅|友情合作|加入我们|天极动态|网站地图|意见反馈|MSN/QQ上看天极
Copyright (C) 1999-2012 Yesky.com, All Rights Reserved 版权所有 天极网络