All Programs are Written and Compiled in Dev C++. So, it may generate some error in case of other compilers and may need some modifications in program. Download Dev C++

Wednesday 26 February 2014

Inserion of a new element at some Location in Tabular Array

//Inserion of a new element at some Location in Tabular Array
#include<iostream.h>
#include<conio.h>
int main()
{
      int a[10],d;
      float b[10],e;
      char c[10][10],f[10];
      int m,i,loc;
      cout<<"Enter no of elements in array";
      cin>>m;
      cout<<"Enter Roll no, Marks & Name"<<endl;
      for(i=0;i<m;i++)
      {
     cin>>a[i]>>b[i];
     cin>>c[i];
      }
     
      cout<<"Enter the Place where to Insert";
      cin>>loc;
      cout<<"Enter details of new Sudent";
      cin>>d>>e>>f;
     
      for(i=m;i>=loc;i--)
      {
                        a[i]=a[i-1];
                        b[i]=b[i-1];
                        strcpy(c[i],c[i-1]);
                        }
      a[loc-1]=d;
      b[loc-1]=e;
      strcpy(c[loc-1],f);
      m=m+1;
//printing Table    
      cout<<"Roll No"<<"\t"<<"Marks"<<"\t"<<"Name"<<endl;
      for(i=0;i<m;i++)
      {
cout<<a[i]<<"\t"<<b[i]<<"\t";
cout<<c[i]<<endl;
      }
getch();
return 0;
}

No comments:

Post a Comment