C Programming code for Reversing Limits of 1D Array – KLE Tech

Write a Modular C Programming Code for Reversing with upper & lower limits 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,low,up;
printf("\nEnter the Lower limit Index: ");
scanf("%d",&low);
printf("\nEnter the Upper limit Index: ");
scanf("%d",&up);

for(i=low,k=up;i<k;i++,k--)
{
temp=A[i];
A[i]=A[k];
A[k]=temp;
}
}

OUTPUT

Enter the size of array
9
Enter elements of the array:
5
6
2
4
3
2
8
4
6
Elements of the array before sorting:
5       6       2       4       3       2       8       4       6
Enter the Lower limit Index: 3

Enter the Upper limit Index: 7

Elements of the array after sorting:
5       6       2       4       8       2       3       4       6
Process returned 0 (0x0)   execution time : 17.505 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 !!!