+ 5

How can print an array from the end to the start?

Suppose I have the array a[4]={3,1,2,5} how can I make it print 5213?

2nd Mar 2018, 12:33 PM
Abubakr Badrelmaarif
Abubakr Badrelmaarif - avatar
5 Answers
+ 15
run a loop from n=no. of elements in array-1 to n=0 //where n correspnds to index value of an element in array
2nd Mar 2018, 12:47 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
2nd Mar 2018, 12:46 PM
Akash Pal
Akash Pal - avatar
+ 3
I have updated my code for you @Abubakr. Now you can find the terms of any array and can reverse it.
3rd Mar 2018, 10:33 PM
Akash Pal
Akash Pal - avatar
+ 2
What if I don't know the number of elements in the array? I heard vectors can help me but I don't know how to use them as I still didn't reach them in the course.
3rd Mar 2018, 7:19 PM
Abubakr Badrelmaarif
Abubakr Badrelmaarif - avatar
0
thanks @Akash!! but I didn't understand the (sizeof(myArr)/sizeof(myArr[0]))-1 part. Shouldn't x=sizeof (myArr) be enough?
4th Mar 2018, 4:03 AM
Abubakr Badrelmaarif
Abubakr Badrelmaarif - avatar