| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

问题点数：0 回复次数：6

#include <stdio.h>
int main()
{
int *p,i;
int a[10]={2,3,5,4,8,9,6,0,11,1};
p=a;
printf("please the original number:\n");
for(i=0;i<10;i++)
printf(" %d",*p++);
printf("%\n");
inv(a,10);
printf("please the inverted number:\n");
for(i=0;i<10;i++)
//printf(" %d",*p++);
printf(" %d",a[i]);

printf("%\n");
return 0;
}

*p++中，  *的优先级要高于 ++，应该改为printf(" %d",*（p++）);

for(i=0;i<10;i++)
printf(" %d",*p++);

for(i=0;i<10;i++)
//printf(" %d",*p++);

```#include <stdio.h>

int main( void )
{
int a[10] = { 2, 3, 5, 4, 8, 9, 6, 0, 11, 1 };

printf( "the original number:" );
for( int* p=a; p!=a+sizeof(a)/sizeof(*a); ++p )
printf( " %d", *p );
putchar( '\n' );

for( int *p=a, *q=a+sizeof(a)/sizeof(*a)-1; p<q; ++p,--q )
{
int tmp = *p;
*p = *q;
*q = tmp;
}

printf( "the inverted number:");
for( int* p=a; p!=a+sizeof(a)/sizeof(*a); ++p )
printf( " %d", *p );
putchar( '\n' );
}```

the original number: 2 3 5 4 8 9 6 0 11 1
the inverted number: 1 11 0 6 9 8 4 5 3 2

int inv(int in[],int len)
{
int *i,*j,*p,k,m=(len-1)/2;
i=in;
j=in+len-1;
p=in+m;
for(;i<=p;i++,j--)
{

k=*i;
*i=*j;
*j=k;
}
return 0;
}

• 7
• 1/1页
• 1

Powered by Discuz, Processed in 0.061450 second(s), 8 queries.