New Update Launched Contact Us Download Now!

C program to perform basic array operations

Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated
Note: This program is done without pointers, hence modified values will not reflect on the original array!

C Source Code

#include<stdio.h>
void insert(int[],int);
void sort(int[],int);
void deletion(int[],int);
void search(int[],int);
void main()
{ int q,A[50],n,i;
printf("\t\t**************************\n\n\t\t\tArray Operator\n\t\t\tBy Jace Joji\n\n\t\t**************************");
printf("\nEnter array size:");
scanf("%d",&n);
printf("Enter Array:");
for(i=0;i<n;i++)
scanf("%d",&A[i]);
printf("Your array is:");
for(i=0;i<n;i++)
printf("\t%d",A[i]);
do{
printf("\nMenu Options:\n1)Insertion\n2)Sorting\n3)Deletion\n4)Search\n>>>");
scanf("%d",&q);
switch(q){
case 1:insert(A,n);
break;
case 2:sort(A,n);
break;
case 3:deletion(A,n);
break;
case 4:search(A,n);
break;
};
printf("\nPress 0 to return to main menu\nPress 9 to exit()\n>>>");
scanf("%d",&q);
if(q!=0)
printf("Thank you for using our program");
}while(q==0);

}
void search(int A[],int n)
{ int i,s;
printf("\n Enter search parameter:");
scanf("%d",&s);
for(i=0;i<n;i++)
if(s==A[i]) 
{ printf("\nSearch element found at %dth position",i+1);
break;
}
else
printf("\nSearch element not found at %dth position",i+1);
} 

void insert(int A[],int n)
{ int i,s,j;
printf("\n Enter insertion Item:");
scanf("%d",&s);
printf("\n Enter insertion location(index):");
scanf("%d",&j);
for(i=n-1;i>=j;i--)
A[i+1] = A[i];
A[j]=s;
n=n+1;
printf("The modified array is");
for(i=0;i<n;i++)
printf("\t%d",A[i]);
}
void deletion(int A[],int n)
{ int i,j;
printf("\n Enter index of element to be deleted:");
scanf("%d",&j);
for(i=j;i=n-1;i++)
A[i]= A[i+1];
n=n-1;
printf("The modified array is");
for(i=0;i<n;i++)
printf("\t%d",A[i]);
}
void sort(int A[],int n)
{ int i,j,temp;
for(i=0;i<n-1;i++)
 for(j=0;j<n-i-1;j++)
 {if(A[j]>A[j+1])
  {temp=A[j];
   A[j]=A[j+1];
   A[j+1]=temp;
   }}
   printf("The sorted array is:");
   for(i=0;i<n;i++)
   printf("\t %d",A[i]);
}


Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.