Thursday 24 December 2015

Reverse an Array in C

C program to reverse an array: This program reverses the array elements. For example if a is an array of integers with three elements such that
a[0] = 1
a[1] = 2
a[2] = 3
Then on reversing the array will be
a[0] = 3
a[1] = 2
a[0] = 1


#include <stdio.h>
 
int main()
{
   int n, c, d, a[100], b[100];
 
   printf("Enter the number of elements in array\n");
   scanf("%d", &n);
 
   printf("Enter the array elements\n");
 
   for (c = 0; c < n ; c++)
      scanf("%d", &a[c]);

   for (c = n - 1, d = 0; c >= 0; c--, d++)
      b[d] = a[c];
 
 
   for (c = 0; c < n; c++)
      a[c] = b[c];
 
   printf("Reverse array is\n");
 
   for (c = 0; c < n; c++)
      printf("%d\n", a[c]);
 
   return 0;
}

1 comment:

  1. Casino Slots Mobile App - JtmHub
    With the launch of the 경산 출장샵 Casino Slots Mobile App, you can play free slot machine 정읍 출장안마 games and win prizes 태백 출장안마 in real money. 보령 출장샵 It's 김제 출장안마 easy to download the app on your device

    ReplyDelete