Reverse array

Q. Write a c program to accept n elements from user and reverse all elements.


Ans.

/*c program for reverse an array*/
#include<stdio.h>
#include<conio.h>
#define S 50
int main()
{
 int i,num,mid;
 float arr[S],tmp;
 printf("Ener total number of element in array : ");
 scanf("%d", &num);
 for(i=0; i<num; i++)
 {
   printf("Enter %d element : ",i+1);
   scanf("%f", &arr[i]);
 }
 mid = num/2;
 for(i=0; i<mid; i++)
 {
   /*swapping*/
   tmp = arr[i];
   arr[i]= arr[num-1-i];
   arr[num-1-i] = tmp;
 }
 printf("\n-- Array in reverse order --\n\n");
 for(i=0; i<num; i++)
    printf("\t%.2f\n",arr[i]);
 getch();
 return 0;
}

/************Output************/


Output of accept n elements from user and reverse all elements C program
Screen shot for reverse array C program

Related program:
  1. Reverse array using simple C program

Comments