c语言-C程序设计(第四版)谭浩强_课后习题答案第11章

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
int main()
{
float x=5.0,x1=3.0,x2=8.0;
char d='f';
PR(d,x);
PRINT1(d,x);
PRINT2(d,x1,x2);
return 0;
}
11-6
#include<stdio.h>
#define PR printf
#define NL "\n"
#define Fs "%f"
int main()
{
int a,b,t;
printf("input two integer a,b:");
scanf("%d,%d",&a,&b);
swap(a,b);
printf("Now,a=%d,b=%d\n",a,b);
return 0;
}
11-2
#include <stdio.h>
#define SURPLUS(a,b)((a)%(b))
return 0;
}
}
return 0;
}
11-8-1
#include<stdio.h>
int main()
{int max(int x,int y,int z);
int a,b,c;
printf("input three integer: ");
scanf("%d,%d,%d",&a,&b,&c);
printf("max=%d\n",max(a,b,c));
int main()
{
int year;
printf("\ninput year:");
scanf("%d",&year);
if(LEAP_YEAR(year))
printf("%d is a leap year.\n",year);
else
printf("%d is not a leap year. \n",year);
scanf(Fs,&b);
scanf(Fs,&c);
PR(NL);
PR("output one floating number each line:\n");
PR(F1,a);
PR(F1,b);
PR(F1,c);
PR(NL);
PR("output two floating number:\n");
PR(F2,a,b);
case 2: printf("input float: ");
scanf("%f",&f);
FLOAT(f);
break;
case 3: printf("input string: ");
scanf("%s",&s);
STRING(s);
break;
default: printf("input error!\n");
PR(F1,c);
PR(NL);
PR("output three floating number:\n");
PR(F3,a,b,c);
return 0;
}
11-7
#include <stdio.h>
#include "format.h"
int main ()
{
int d,num;
float f;
char s[80];
#define F "%6.2f"
#define F1 F NL
#define F2 F"\t" F NL
#define F3 F"\t" F "\t" F NL
int main()
{float a,b,c;
PR("input three floating number a,b,c:\n");
scanf(Fs,&a);
int main()
{
int a,b;
printf("input two integer a,b:");
scanf("%d,%d",&a,&b);
printf("remainder is %d\n",SURPLUS(a,b));
return 0;
}
11-4
#include<stdio.h>
#define LEAP_YEAR(y)((y%4==0)&&(y%100!=0)||(y%400==0))
return 0;
}
11-10
#include <stdio.h>
#define MAX 80
#define CHANGE 1
int main()
{
char str[MAX];
int i;
printf("input text:\n");
gets(str);
#if(CHANGE)
{for(i=0;i<MAX;i++)
{if(str[i]!='\0')
if(str[i]>='a'&&str[i]<'z'||str[i]>='A'&&str[i]<='Z')
str[i]+=1;
else if(str[i]=='z'||str[i]=='Z')
str[i]-=25;
}
}
#endif
printf("output:\n%swenku.baidu.comn",str);
printf("choice data format: 1-integer,2-float,3-string:");
scanf("%d",&num);
switch(num)
{case 1: printf("input integer: ");
scanf("%d",&d);
INTEGER(d);
break;
return 0;
}
11-5
#include <stdio.h>
#define NL putchar('\n')
#define PR(format,value) printf("value=%format\t",(value))
#define PRINT1(f,x1) PR(f,x1);NL
#define PRINT2(f,x1,x2) PR(f,x1);PRINT1(f,x2)
return 0;
}
11-8-2
#include<stdio.h>
#define MAX(a,b)((a)>(b)?(a):(b))
int main()
{
int a,b,c;
printf("input three integer: ");
scanf("%d,%d,%d",&a,&b,&c);
printf("max=%d\n",MAX(MAX(a,b),c));
C程序设计(第四版)谭浩强_课后习题答案第11章
第11章常见错误分析374
附录390附录A在Visual C++ 6.0环境下运行C程序的方法390
附录CC语言中的关键字398
附录D运算符和结合性398
附录EC语言常用语法提要400
附录FC库函数404
11-1
#include <stdio.h>
#define swap(a,b)t=b;b=a;a=t
相关文档
最新文档