Programming's = loads of fun!!!!!!! #include <stdio.h> #include <conio.h> #define size 10 void main() { int a[size],del,j,i; clrscr(); for(i=0;i<size;i++) {j=i+1; printf(" Enter the %d element of array",j); scanf("%d",&a[i]);} printf(" Enter the element to be deleted"); scanf("%d",&del); del--; for(i=del;i<size-1;i++) a[i]=a[i+1]; a[size-1]=0; printf(" Element has been deleted"); printf(" Array now is..... "); for(i=0;i<size;i++) printf("%d ",a[i]); getch(); }
Another way of writing the program is to just assign value zero to the specified element.
#include <stdio.h> #include <conio.h> #define size 10 void main() { int a[size],del,j,i; clrscr(); for(i=0;i<size;i++) {j=i+1; printf(" Enter the %d element of array",j); scanf("%d",&a[i]);} printf(" Enter the element to be deleted"); scanf("%d",&del); /*Corresponding element assigned value zero*/ a[--del]=0; for(i=0;i<size;i++) printf("%d ",a[i]); getch(); }
#include <stdio.h> //#include <conio.h> #include"stdafx.h" #include"malloc.h" //#define size 10 void main() { int *a,*b,size, del,j=0,i; printf("enter the size of the array "); scanf("%d",&size); a=(int*)malloc(size*sizeof(int)); b=(int*)malloc(size*sizeof(int)); for(i=0;i<=size-1;i++) { printf("enter the value in an array "); scanf("%d",&a[i]); } printf("enter the value to be deleted "); scanf("%d", &del); for(i=0;i<=size-1;i++) { if(a[i]!=del) { b[j]=a[i]; j++; } } for(i=0;i<j;i++) printf("%d ", b[i]);
Programming's = loads of fun!!!!!!! #include <stdio.h> #include <conio.h> #define size 10 void main() { int a[size],del,j,i; clrscr(); for(i=0;i<size;i++) {j=i+1; printf(" Enter the %d element of array",j); scanf("%d",&a[i]);} printf(" Enter the element to be deleted"); scanf("%d",&del); del--; for(i=del;i<size-1;i++) a[i]=a[i+1]; a[size-1]=0; printf(" Element has been deleted"); printf(" Array now is..... "); for(i=0;i<size;i++) printf("%d ",a[i]); getch(); }
#include<stdio.h> #include<conio.h> void main() { int arr[50],i,del,n,f=0; clrscr(); printf(" enter the number of element you want to insert="); scanf("%d",&n); for(i=0;i<n;i++) { printf(" enter element="); scanf("%d",&arr[i]); } printf(" enter the index of element you want to delete"); scanf("%d",&del); for(i=0;i<n;i++); { if(arr[i]==del) f=1; if(f==1) { arr[i]=arr[i+1]; } printf(" %d",arr[i]); }
main() { int a[10]; int key,i,pos,j,n=10; printf("ENtER ThE ArrAY"); for(i=0;i<n;i++) scanf("%d"a[i]); printf("/nenTer thE elEMeNt to DeletE"); scanf("%d",&key); for(i=0;i<n;i++) { if(a[i]==key) { for(j=i;j<n-1;j++) { a[j]=a[j+1]; } n--; } } }
#include<stdio.h> #include<conio.h> void main() { int a[10],i,pos,n; clrscr(); printf("
Enter the size of array:"); scanf("%d",&n); printf("
Enter the elements of array:"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("
Enter the position:"); scanf("%d",&pos); pos=pos-1; for(i=pos;i<n;i++) {
a[i]=a[i+1]; a[n]=0; } printf("
The array with deleted number is:"); for(i=0;i<n;i++) { printf("%d",a[i]); }
you cant do that with out copying it into a new array. since array is not a linked list. hence we use linked list to do such things. you can make an array element zero but it docent mean that you deleted the element.
#include<conio.h> #include<stdio.h> void main() { int a[4],*p,n,i; printf("Enter the elements "); for(i=1;i<=4;i++) { scanf("%d",&a[i]); } p=a; printf("
Enter the position which u want to delete "); scanf("%d",&n); for(i=1;i<=n;i++) { printf("%d ",*p); p++; } p++; for(i=p+1;i<=4;i++) { printf("%d ",*p); p++; } getch(); }
/* Proram to delete an element from array*/ #include<iostream.h> #include<conio.h> #include<stdio.h> void main() { int max,i,a,l=1; int arr[500]; clrscr(); cout<<"enter the maximum no....
->"; cin>>max; if(max>=0) { cout<<"
enter the no. of your choice...
";
for(i=1;i<=max;i++) { printf("%d-> ",l); cin>>arr[i]; l++; } cout<<"
enter the no. of position which you want to delete.....
-> "; cin>>a; if(a<=max) { cout<<"
the updated array is
" "; for(int b=1;b<a;b++) { cout<<arr[b]<<" "; }