下面的这个程序,可以用c++中的T 函数实现,可以减少一个函数,谢谢

#include<stdio.h>#defineM7#defineN7int*small(int*x,int*y);char*big(char*m,char*n);voi... #include<stdio.h>
#define M 7
#define N 7
int *small(int *x,int *y);
char *big(char *m,char *n);
void main()
{
int str1[M]={9,5,6,7,4,10,8};
char str2[N]={'c','i','h','m','t','a','g'};
int i,j;
int *p1,*p2;
char *p3,*p4;
p1=str1;
p2=&str1[6];
p3=str2;
p4=&str2[6];
small(p1,p2);
big(p3,p4);
for(i=0;i<N;i++)
printf("%3ld",str1[i]);
printf("\n");
for(j=0;j<M;j++)
printf("%c",str2[j]);
printf("\n");
}
int *small(int *x,int *y)
{
int k,i;
for( i=0;i<M/2;i++,x++,y--)
{
k=*x;
*x=*y;
*y=k;
}
return 0;
}
char *big(char *m,char *n)
{
int t,j;
for( j=0;j<N/2;j++,m++,n--)
{
t=*m;
*m=*n;
*n=t;
}
return 0;
}
展开
 我来答
千江月success
2013-01-26 · TA获得超过827个赞
知道小有建树答主
回答量:1031
采纳率:100%
帮助的人:935万
展开全部
#include<stdio.h>
#define M 7
#define N 7
template <class T>
T *change(T *x,T *y)
{
int k,i;
for( i=0;i<M/2;i++,x++,y--)
{
k=*x;
*x=*y;
*y=k;
}
return 0;
}
void main()
{
int str1[M]={9,5,6,7,4,10,8};
char str2[N]={'c','i','h','m','t','a','g'};
int i,j;
int *p1,*p2;
char *p3,*p4;
p1=str1;
p2=&str1[6];
p3=str2;
p4=&str2[6];
//small(p1,p2);
//big(p3,p4);
change<int>(p1,p2);
change<char>(p3,p4);
for(i=0;i<N;i++)
printf("%3ld",str1[i]);
printf("\n");
for(j=0;j<M;j++)
printf("%c",str2[j]);
printf("\n");
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式