Answers:
/*Inserting an element into and deleting an element from an array*/ #include<stdio.h> #include<conio.h> void display(int*,int); void insert(int*,int*,int,int); void del(int*,int*,int); int main() { int a[10],noe; int i,pos,nel; printf(" Enter noe"); scanf("%d",&noe); for(i=0;i<noe;i++) scanf("%d",&a[i]); display(a,noe); printf(" Enter the position and element to be inserted"); scanf("%d %d",&pos,&nel); insert(a,&noe,pos,nel); display(a,noe); del(a,&noe,pos); return 0; } void insert(int*p,int *noe,int pos,int nel) { int i; for(i=*noe;i>=pos;i--) { p[i]=p[i-1]; } (*noe)++; p[i]=nel; } void display(int*p,int noe) { int i; for(i=0;i<noe;i++) printf(" %d",p[i]); }
Posted by: B.N.V.R.Ganesh
Contact B.N.V.R.Ganesh
#include<stdio.h> #include<conio.h> void main() { int a[20],i,j,n; clrscr(); printf("Enter the no of element you want to insert in the array : "); scanf("%d",&n); printf("
Enter the Array element :
"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("The array is :
"); for(i=0;i<n;i++) { printf("%d",a[i]); } printf("
Enter the element which you want to insert"); scanf("%d",&j); printf("The array is :
"); for(i=0;i<n+1;i++) { if(i==n) a[i]=j; printf("%d",a[i]); } getch(); }
Posted by: Nikhil jain
Contact Nikhil jain
#include<stdio.h> #include<conio.h> int i,len,pos,num; main() { int a[100]; void insert(int a[],int,int,int) clrscr(); printf("enter integer to be read"); scanf("%d",&len); printf("enter integer"); for("i=0;i<len;i++) { scanf("%d",&a[i]); } printf("enter integer to be inserted"); scanf("%d",&pos); --pos; getch(); return 0; insert(a,len,pos,num); } void insert(int a[],int len,int pos,int num) { for(i=len;i>=pos;i--) { a[i+1]=a[i]; } a[pos]=num; if(pos>len) { printf("insertion outside the array"); } len++; printf("new array"); for(i=0;i<len;i++) { printf("%d
",a[i]); } }
Posted by: priti rachana
Contact priti rachana
#include<stdio.h> #include<conio.h> void main() { int a[10],noe; int i,pos,ele; printf("Enter noe"); scanf("%d",&noe); for(i=0;i<noe;i++) scanf("%d",&a[i]); printf("Enter the position and element to be inserted"); scanf("%d%d",&pos,&ele); for(i=noe;i>=pos;i--) a[i]=a[i-1]; a[pos-1]=ele; for(i=0;i<=noe;i++) printf(" %d",a[i]); getch(); }
Posted by: keerthan shetty
Contact keerthan shetty
#include<stdio.h> #include<conio.h> void insert(int b[],int n,int pos,int item); void main() { int a[6]={10,20,30,40,50},p,c,item; printf("enter item and position for insertion"); scanf("%d%d",&item,&p); printf("array before insertion"); for(c=0;c<=4;c++) { printf("%d
",a[c]); } insert(a,6,p,item); printf("array after insertion"); for(c=0;c<=5;c++) { printf("%d
",a[c]); } getch(); } void(int b[],int n,int pos,int item) { int c; c=n-1; while(c>pos) { b[c]=b[c-1]; c--; } b[c]=item; }
Posted by: RENUKA
Contact RENUKA
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
There should not be any Spelling Mistakes.
There should not be any Gramatical Errors.
Answers must not contain any bad words.
Answers should not be the repeat of same answer, already approved.
Answer should be complete in itself.