Exp 1
Exp 1
#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
*/