reverse order of elements in array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

reverse order of elements in array

what is wrong in this ?? if there any mistake correct and reply #include <stdio.h> void main() { int b,n; int a[n]; int i,j; printf("Enter the number of elements\n"); scanf("%d",&n); for(b=0;b<n;b++) scanf("%d", &a[b]); printf("The reverse order is \n"); for(i=1;i<=n;i++) { j=n-i; printf("%d\n",a[j]); } }

16th Oct 2017, 11:30 AM
NALLAPALEM NEERAJ SRINIVAS
1 Answer
+ 3
the array declaration is wrong int a[n] ,your are assigning the value of n after the above statement. if you do then the value of n should be constant and it should be after the header #define n 10 then you can proceed with int a[n] Because in c and c++ the declaration should be at the initial level but in case of java u can declare variable Any where in the program.
16th Oct 2017, 1:15 PM
Nanda Balakrishnan