I am trying to print a array in Reverse order by using the recursive function but I am getting so many error can someone guide me through the process please where I am making the mistakes.
#include<stdio.h>
int PrintArray(int a[],int k) {
int z;
while(k>0) {
z=k-1;
PrintArray(a[],z);
printf("%d ",a[k]);
}
}
int main() {
int n,i;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",a[i]);
PrintArray(a[],n);
return 0;
}
PrintArray(a[],n)should bePrintArray(a,n). But if you known, you don't need recursion to print the array backwards. A simple loop will do. So I think there's something about the assignment that you didn't understand.printArrayis recursive, but aswell uses a loop to print the array in reverse order. This leads to misbehaviour, since elementxin the array will be printedn - xtimes this way.