Sunday 27 January 2013

Write a program to Split an array into 2 arrays


#include<iostream.h>
#include<conio.h>
void main()
{
            int a[10],i,n,b[10],c[10],mid;
            clrscr();
            cout<<"how many element you want in array A=";
            cin>>n;
            for(i=0;i<n;i++)
            {
                        cout<<"enter the value of a["<<i<<"]=";
                        cin>>a[i];
            }//end of for loop
            cout<<"\n the element are"<<endl;
            for(i=0;i<n;i++)
            {
                        cout<<"element of a["<<i<<"]="<<a[i]<<endl;
            }//end of for loop
            cout<<endl<<"WE HAVE SPILT ARRAY A INTO ARRAY B AND ARRAY C"<<endl<<endl;
            mid=n/2;
            cout<<"ELEMENT OF ARRAY B ARE\n";
            for(i=0;i<n;i++)
            {
                        if(i<=mid-1)
                        {
                                    b[i]=a[i];
                                    cout<<"element of b["<<i<<"]=";
                                    cout<<b[i]<<endl;
                        }
            }//end of for loop
            int j;
            cout<<"\n ELEMENT OF ARRAY C ARE"<<endl;
            for(i=mid,j=0;i<n;i++,j++)
            {
                        c[j]=a[i];
                        cout<<"element of c["<<j<<"]=";
                        cout<<c[j]<<endl;
            }
            j--;

getch();
}

No comments:

Post a Comment