C Programming code for Reversing of an Array – KLE Tech

Write a Modular C Programming Code for the Reverse of a 1D Array?

CODE:

#include<stdio.h>

void read(int A[],int n);
void display(int A[],int n);
void reverse(int A[],int n);
main()
{
int A[30],i,n,temp,j,k;
printf("Enter the size of array\n");
scanf("%d",&n);
printf("Enter elements of the array:\n");
read(A,n); 
printf("Elements of the array before sorting:\n");
display(A,n); 
reverse(A,n); 
printf("\nElements of the array after sorting:\n");
display(A,n); 
}
void read(int A[],int n)
{
int i;
for(i=0;i<n;i++)
scanf("%d",&A[i]); 
}
void display(int A[30],int n)
{
int i;
for(i=0;i<n;i++)
printf("%d\t",A[i]); 
}
void reverse(int A[],int n)
{
int i,k,temp;
for(i=0,k=n-1;i<k;i++,k--)
{
temp=A[i];
A[i]=A[k];
A[k]=temp;
}
}

OUTPUT

Enter the size of Array: 3
Enter elements of the array:
2
6
5
Elements of the array before sorting:
2       6       5
Elements of the array after sorting:
5       6       2
Process returned 0 (0x0)   execution time : 8.916 s
Press any key to continue.

 

Please find some more codes of 1D Arrays, 2D Arrays, Pointers on the below page:

Top 100+ C Programming codes – KLE Technological University

 







Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

Welcome to FactsPrime

Sorry, We have detected that you have activated Ad-Blocker. Please Consider supporting us by disabling your Ad Blocker, It helps us in maintaining this website. To View the content, Please disable adblocker and refresh the page.

Thank You !!!