使用递归函数,将一个整型数组倒序输出。(数组用了随机数,每次的数组都不同,只用了调用,遗憾没用递归。。可以把for循环换成递归)

来源:互联网 发布:java数据分析工具 编辑:程序博客网 时间:2024/05/27 21:04
#include <stdio.h>#include<stdlib.h>#include<time.h>#define N 10#define n 13void 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);  }  }

0 0
原创粉丝点击