Answers for "printing array in reverse order c++"

C++
0

printing an array backwards in c++

#include <iostream>
 
// Print contents of an array in reverse order in C++
// using array indices
int main()
{
    int arr[] = { 10, 20, 30, 40 };
    size_t n = sizeof(arr)/sizeof(arr[0]);
 
    // iterate backwards over the elements of an array
    for (int i = n - 1; i >= 0; i--) {
        std::cout << arr[i] << ' ';
    }
 
    return 0;
}
Posted by: Guest on March-09-2021
0

print array in reverse order

#include <stdio.h>

int main() {
   int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
   int loop;

   for(loop = 9; loop >= 0; loop--)
      printf("%d ", array[loop]);
      
   return 0;
}
Posted by: Guest on September-14-2021

Browse Popular Code Answers by Language