Professional Documents
Culture Documents
Array
Array
Array
ENGINEERING
SUBMITED BY
DECLARATION :-
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],i,p,n;
clrscr();
printf("\n how many element u enter: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
}
printf("\n Enter position : ");
scanf("%d",&p);
for(i=p;i<=n-1;i++)
{
a[i]=a[i+1];
}
n--;
for(i=0;i<n;i++)
{
printf("\n %d",a[i]);
}
getch();
OUTPUT
How many number you enter:- 4
1
2
54
65
Enter the position:-2
1
2
65
INSERTION
This operation can be used to insert an arbitary
element at specified location in an array.
W.A.P TO INSERT ELEMENTS IN ARRAY
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,n,p,x;
clrscr();
printf("\n how many element you enter : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\n Enter the position : ");
scanf("%d",&p);
printf("\n Enter new value : ");
scanf("%d",&x);
for(i=n-1;i>=p;i--)
{
a[i+1]=a[i];
}
a[p]=x;
n++;
for(i=0;i<n;i++)
{
printf("\n %d",a[i]);
}
OUTPUT
How many elements you enter:- 4
1
2
54
65
Enter the position:-2
Enter the new value:- 3
1
2
3
54
65
SEARCHING
A searching is a method of locating a specific item of
information in a larger collection of data.
For example…
Program to search for an elements in an array
#include<stdio.h>
#include<conio.h>
void main()
{
int a[30],x,n,i;
/*
a-for sorting of data
b-elements to be searched
n-no of elements in the array
i-scanning of array
*/
printf("\n Enter no of elements:");
scanf("%d",&n);
printf("\n Enter the values: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("eneter the elements to be searched");
scanf("%d",&x);
i=0;
if(i<n)
printf("Found at the location =%d",i+1);
else
printf("\n not found);
getch();
}
OUTPUT:
Enter no of elements : 3
Enter the values: 55 56 57
Enter the elements to be searched : 56
Found at the Location =2
SORTING
REVERSING ARRAY