Tuesday 22 January 2013

Program to insert number into an array

| |














#include<iostream>

using namespace std;

int main()
{
    int x,n,p[n],q[n],i,j,a;
    cout<<"Enter the number of elements in array :""\n";
    cin>>n;
    cout<<"Enter "<<n<<" integers in ascending or descending order:\n";
    for(i=1;i<=n;i++)
    {
                    cin>>x;
                    p[i]=x;
                    q[i]=x;
                    }
    cout<<"Enter the no. you want to insert :""\n";
    cin>>a;
    for(i=1;i<=n;i++)

    {
                    if(p[i]>a)
                    {
                                  break;
                                  }
                                  }
    p[i]=a;
    for(j=i+1;j<=n+1;j++)
    {
                         p[j]=q[j-1];
                         }
 
    for(i=1;i<=(n+1);i++)
    {
                         cout<<p[i]<<"\n";
                         }
    system("pause");
    return 0;
}
   


Program to insert number into an array


Related Posts Plugin for WordPress, Blogger...
Powered by Blogger.