第十章
10.1
#include <iostream>
void main()
{
void swap(int *p,int *q);
int x,y,z;
int *p1,*p2,*p3;
printf("输入三个整数\n\n");
scanf("%d%d%d",&x,&y,&z);
p1=&x;
p2=&y;
p3=&z;
if(x>y) swap(p1,p2);
if(x>z) swap(p1,p3);
if(y>z) swap(p2,p3);
printf("\n\n三个数由小到达输出为:%d %d %d\n\n",x,y,z);
}
void swap(int *p,int *q)
{
int temp;
temp=*p;
*p=*q;
*q=temp;
}
10.2
#include <iostream>
#include <string>
#define N 80
void main()
{
void swap(char *p,char *q);
char str1[N],str2[N],str3[N];
printf("请输入三个字符串\n\n");
scanf("%s",str1);
scanf("%s",str2);
scanf("%s",str3);
if(strcmp(str1,str2)>0) swap(str1,str2);
if(strcmp(str1,str3)>0) swap(str1,str3);
if(strcmp(str2,str3)>0) swap(str2,str3);
printf("\n\n三个字符串由小到大排列,分别为:\n\n%s\n%s\n%s\n",str1,str2,str3);
}
void swap(char *p,char *q)
{
char str[N];
strcpy(str,p);
strcpy(p,q);
strcpy(q,str);
}
10.3
#include <iostream>
#define N 10
void main()
{
void input(int num[N]);
void swap(int *p,int *q);
void exchange(int num[N]);
void output(int num[N]);
int num[N];
input(num);
exchange(num);
output(num);
}
void input(int num[N])
{
int i;
printf("输入十个整数\n\n");
for(i=0;i<N;i++)
{
scanf("%d",&num[i]);
}
}
10.4
#include <iostream>
#define N 10
#define M 3
void main()
{
void move(int num[N],int n,int m);
int num[N];
int i;
printf("输入%d个整数\n\n",N);
for(i=0;i<N;i++)
{
scanf("%d",&num[i]);
}
move(num,N,M);
printf("\n\n调整后的%d个整数为:\n\n",N);
for(i=0;i<N;i++)
{
printf("%d ",num[i]);
}
printf("\n\n");
}
void swap(int *p,int *q)
{
int temp;
temp=*p;
*p=*q;
*q=temp;
}
void move(int num[N],int n,int m)
{
int *p,*num_end;
int temp;
num_end=num+n;
temp=*(num_end-1);
for(p=num_end-1;p>=num;p--)
*p=*(p-1);
*num=temp;
m--;
if(m>0) move(num,n,m);
}
10.5
#include <iostream>
#define N 8
void main()
{
void leave(int num[N]);
int num[N];
int i,*p;
p=num;
for(i=0;i<N;i++)
*(p+i)=i+1;
leave(num);
while(*p==0) p++;
printf("最后留下的是第%d个人\n\n",*p);
}
void leave(int num[N])
{
int *p;
int i=0,k=0,m=0;
p=num;
while(m<N-1)
{
if(*(p+i)!=0) k++;
if(k==3)
{
*(p+i)=0;
k=0;
m++;
}
i++;
if(i==N) i=0;
}
}
10.6
#include <iostream>
#define N 10
void main()
{
int count(char str[N]);
int i;
char str[N];
printf("输入一个字符串\n\n");
gets(str);
printf("\n\n字符串长度为:%d\n\n",count(str));
}
int count(char str[N])
{
char *p;
int i=0;
p=str;
while(*p!='\0')
{
i++;
p++;
}
return(i);
}
10.7
#include <iostream>
#define N 80
#define M 4
void main()
{
void copy(char str1[N],char str2[N]);
char str1[N],
c语言程序设计第三版谭浩强第十章指针_计算机软件及应用_IT/计算机_专业资料... 2013年注会设计统考真题及答案 104份文档 2014年驾照交规 2014年1月1日起“...
c语言程序设计第三版谭浩强第十一章结构体_计算机软件及应用_IT/计算机_专业资料。c语言程序设计,谭浩强第三版 2005年首发 清华大学出版社出版...
(max<c) max=c; printf(“最大数为:“%d”,max); } 第三章 file:///D/程序设计/C语言程序设计第三版谭浩强课后习题答案1~13章.txt[2010-7-20 10...
谭浩强C语言程序设计教程(第三版)课后习题答案_理学_高等教育_教育专区。3.30 编写程序,把560分钟换算成用小时和分钟表示,然后进行输出。 ※程序如下※ main( ...
谭浩强c语言程序设计(第三版)习题答案_IT/计算机_专业资料。最佳答案 1.5请参照本章例题,编写一个C程序,输出以下信息: *** Very Goodj! *** 解: main(...
C语言程序设计答案(第三版)谭浩强_工学_高等教育_教育专区。C语言程序设计答案第一章 1.6 main() {int a,b,c,max; printf("input three numbers:\n")...
C程序设计(第三版)习题答案(10章) 谭浩强著(3)_官田百度空间 百度首页 登录 官田有你,生活将会更精彩。 主页博客相册个人档案 好友 查看文章 C程序...
谭浩强_C语言程序设计(第三版)课后习题答案_工学_高等教育_教育专区。程序是在 VC6.0 下编译的,所以头文件和 TC 的不太一样! 4-8 #include <iostream> ...
谭浩强 C语言程序设计(第三版)课后习题答案_IT认证_资格考试/认证_教育专区。很实用的学习资料程序是在 VC6.0 下编译的,所以头文件和 TC 的不太一样! 4-...
C语言程序设计第三版谭浩强课后习题答案完整版_教育学_高等教育_教育专区。c语言C 语言程序设计第三版谭浩强 课后习题答案完整版 第一章 1.5 请参照本章例题...
热门文档