#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int s,n,i,p,a[50];
clrscr();
cout<<"Enter number of students : ";
cin>>n;
cout<<"Enter the marks : ";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter the marks to be deleted : ";
cin>>s;
for(i=0;i<n;i++)
if(a[i]==s)
{
p=i;
break;
}
for(i=p;i<n-1;i++)
a[i]=a[i+1];
cout<<"The new mark list is : ";
for(i=0;i<n-1;i++)
cout<<a[i];
getch();
}
#include<conio.h>
#include<stdlib.h>
void main()
{
int s,n,i,p,a[50];
clrscr();
cout<<"Enter number of students : ";
cin>>n;
cout<<"Enter the marks : ";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter the marks to be deleted : ";
cin>>s;
for(i=0;i<n;i++)
if(a[i]==s)
{
p=i;
break;
}
for(i=p;i<n-1;i++)
a[i]=a[i+1];
cout<<"The new mark list is : ";
for(i=0;i<n-1;i++)
cout<<a[i];
getch();
}
Delete an Element from Array in C++
ReplyDeleteOh great