0% found this document useful (0 votes)
12 views2 pages

Exp 1

Err

Uploaded by

handearyan40
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Exp 1

Err

Uploaded by

handearyan40
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

//Progran to Insert an element into one dimensional array

#include<stdio.h>
#include<conio.h>
void main()
{
int x,i,max=10,pos,K,n,a[10];
clrscr();
printf("Enter number of element");
scanf("%d",&n);
if(n<max)
{
printf("Enter the element:\n");
for(i=0;i<n; i++)
{
printf("Enter element %d\t",i+1);
scanf("%d",&a[i]);
}
printf("Array");
for(i=0;i<n;i++)
{
printf("\n element no %d is %d",i+1,a[i]);
}
printf("\n Enter the element to be added:");
scanf("%d",&x);
printf("Enter the postion of the element where element to be added");
scanf("%d",&pos);
for(i=n;i>=pos;i--)
{
a[i]=a[i-1];
}
a[pos-1]=x;
printf("Array with element inserted:");
for(i=0;i<n+1;i++)
{
printf("\n Element no %d is %d",i+1,a[i]);
}
}
else
{
printf("Memory not available....\n try again 1=y,2=n");
scanf("%d",&K);
if(K==1)
main();
else
exit();
}
getch();
}

//OUTPUT
/*Enter number of element5
Enter the element:
Enter element 1 23
Enter element 2 32
Enter element 3 65
Enter element 4 12
Enter element 5 45
Array
element no 1 is 23
element no 2 is 32
element no 3 is 65
element no 4 is 12
element no 5 is 45
Enter the position of element to be added:89
Enter the postion of the element where element to be added1
Array with element inserted:
Element no 1 is 89
Element no 2 is 23
Element no 3 is 32
Element no 4 is 65
Element no 5 is 12
Element no 6 is 45
*/

You might also like