ARRAY(1)

0
10
views


#include #include int a[100],ch,n,i,ele,pos,j; int flag=0; int main() { while(1) { printf(“welcome to array world\n”); printf(“1.create an array\n2.display the array elements\n3.insert an element to array\n4.delete an element from array\n5.exit\n”); printf(“enter your choice\n”); scanf(“%d”,&ch); switch(ch) { case 1:createarray(); break; case 2:displayarray(); break; case 3:insert(); break; case 4:delete(); break; case 5:exit(0); break; defalt:printf(“enter correct choice\n”); } } } int createarray() { if(flag!=0) { printf(“array is already created\n”); return 0; } else { printf(“enter the size of an array\n”); scanf(“%d”,&n); printf(“enter the array elements into the array\n”); for(i=0;in) { printf(“invalid position\n”); return 0; } for(j=0;j>=pos;j–) { a[j+1]=a[j]; } a[pos]=ele; n=n+1; printf(“element is inserted succesfully at postion %d”,pos); } int delete() { if(flag==0) { printf(“array is not yet created\n”); return 0; } else if(n<=0) { printf(“array is empty\n”); return 0; } else { printf(“enter the position between 0 and %d\n”,n-1); scanf(“%d”,&pos); } if(pos<0||pos>n-1) { printf(“invalid postion\n”); return 0; } for(j=pos;j<=n-1;j++) { a[j]=a[j+1]; } n=n-1; printf(“element is deleted successfully at postion %d”,pos); }

LEAVE A REPLY

Please enter your comment!
Please enter your name here