C Program to reverse an array.

#include <stdio.h>
#include <string.h>

int main () {

   char arr[100];
   char rev[100];
   int n,i,j;

   printf("Enter the number of element in the array\n");
   scanf("%d", &n );

   for(i=0;i<n;i++)
   {
      scanf("%c", &arr[i] );
   }

   printf("Entered array is %s\n", arr);

   /* Reversing the array */
   for(i=0 ; n>0 ; i++,n--)
   {
      rev[i] = arr[n-1];
   }

   printf("Entered array is %s\n", rev);

   return 0;
}



No comments:

Post a Comment