#include <stdio.h>
#include<stdlib.h>
#include<time.h>
#define N 10
#define n 13
void main()
{
void fun(int a[],int);
int i,a[N],temp;
srand(time(0));
printf("The positive order is:\n");
for(i=0;i<N;i++)
{
temp=rand()%n;
a[i]=temp;
printf("%3d",a[i]);
}
printf("\nThe inverted order is:\n");
fun(a,N);
}
void fun(int a[],int i)
{
if(i>0)
{
printf("%-3d",a[i-1]);
fun(a,--i);
}
}
使用递归函数,将一个整型数组倒序输出。(数组用了随机数,每次的数组都不同,只用了调用,遗憾没用递归。。可以把for循环换成递归)
最新推荐文章于 2022-10-28 17:15:57 发布