#include "iostream.h"
void main()
{
int i,m,j,a[7]={1,2,4,5,6,7};
for(i=0;i<6;i++)
cout<<a[i]<<" ";
cout<<endl;
cout<<"please enter a number"<<endl;
cin>>j;
for(i=0;i<6;i++)
{
if(a[i]>j)
break;
}
m=i;
for(i=6;i>m;i--)
{
a[i]=a[i-1];
}
a[i]=j;
for(i=0;i<=6;i++)
cout<<a[i]<<" ";
cout<<endl;
}
#include<iostream.h>
int main()
{
int i,j,Array[7]={1,2,4,5,6,7};
cout<<"显示原始数据:"<<endl;
for(int m=0;m<sizeof(Array)/4-1;m++)
cout<<Array[m]<<" ";
cout<<endl;
cout<<"请输入你要插入的数字:";
cin>>j;
for(int n=sizeof(Array)/4-2;n>0;n--)
if(Array[n]>=j)
Array[n+1]=Array[n];
else
{
Array[n+1]=j;
break;
}
cout<<"显示修改后数据:"<<endl;
for(i=0;i<sizeof(Array)/4;i++)
cout<<Array[i]<<" ";
cout<<endl;
return 0;
}
其实都是大同小异
思路都是差不多的