Không biết sai ở đâu mà không chèn được phần tử ạ
#include<iostream>
#include<stdio.h>
using namespace std;
void nhap(int a[],int n)
{
for(int i=0;i<n;i++)
{
cout<<"\nNhap phan tu thu "<<i+1<<": ";cin>>a[i];
}
}
void xuat(int a[],int n)
{
for(int i=0;i<n;i++)
{
cout<<"\nPhan tu thu "<<i+1<<": "<<a[i]<<" ";
}
}
void sapxep(int a[],int n)
{
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(a[i]<a[j])
{
swap(a[i],a[j]);
}
}
}
}
void chenx(int a[],int &n,int x)
{
int dem=0;
cout<<"\nNhap x: ";cin>>x;
for(int i=0;i<n;i++)
{
if(a[i]==x)
{
dem++;}
}
if(dem!=0)
{
cout<<"\nCo phan tu x= "<<x;
}
else{
cout<<"\nKhong co phan tu x= "<<x;
cout<<"\nChen phan tu x vao mang: ";
n++;
a[n]=x;
}
}
main()
{
int n;int a[100];int x;
do{
cout<<"Nhap n: ";cin>>n;
} while(n<=0||n>=100);
nhap(a,n);
xuat(a,n);
sapxep(a,n);
cout<<"\nSau khi sap xep giam dan la:";
xuat(a,n);
chenx(a,n,x);
xuat(a,n);
}