21
321
4321
怎么才能实现呢?
正确程序已经给出了
就不写了
无聊,写个递归逆序打印的玩玩
[CODE]
#include <stdio.h>
#include <stdlib.h>
typedef unsigned long ULONG;
typedef void VOID;
#define IN
#define OUT
VOID reverseOutput( IN ULONG *pulArray, IN ULONG ulLeft, IN ULONG ulRight );
int main()
{
ULONG ulInputSize;
ULONG *pulArray;
ULONG i;
printf("Please input array size: \r\n");
scanf("%ul", &ulInputSize);
if ( NULL == (pulArray = (ULONG *)malloc(ulInputSize * sizeof(ULONG))) )
{
exit(1);
}
for ( i = 0; i < ulInputSize; i++ )
{
pulArray[i] = i + 1;
}
reverseOutput(pulArray, 0, ulInputSize - 1);
return 0;
}
VOID reverseOutput( IN ULONG *pulArray, IN ULONG ulLeft, IN ULONG ulRight )
{
if ( ulLeft > ulRight )
{
return;
}
if ( ulLeft == ulRight )
{
printf("%lu\n", pulArray[ulLeft]);
return;
}
printf("%lu ", pulArray[ulRight]);
reverseOutput(pulArray, ulLeft + 1, ulRight - 1);
printf("%lu ", pulArray[ulLeft]);
}
[/CODE]
[此贴子已经被作者于2007-10-9 20:47:25编辑过]