//Merging at Begining of a Tabular Array
#include<iostream.h>
#include<conio.h>
int main()
{
int a[10],d[10];
float b[10],e[10];
char c[10][10],f[10][10];
int m,n,i,j;
cout<<"Enter no of elements in List 1 & List 2";
cin>>m>>n;
cout<<"Enter Roll no, Marks & Name of List 1"<<endl;
for(i=0;i<m;i++)
{
cin>>a[i]>>b[i];
cin>>c[i];
}
cout<<"Enter Roll no, Marks & Name of List 2"<<endl;
for(j=0;j<n;j++)
{
cin>>d[j]>>e[j];
cin>>f[j];
}
//shifting
for(i=m+n;i>=n;i--)
{
a[i]=a[i-n];
b[i]=b[i-n];
strcpy(c[i],c[i-n]);
}
//merging
for(i=0;i<n;i++)
{
a[i]=d[i];
b[i]=e[i];
strcpy(c[i],f[i]);
}
//printing Table
cout<<"Roll No"<<"\t"<<"Marks"<<"\t"<<"Name"<<endl;
for(i=0;i<m+n;i++)
{
cout<<a[i]<<"\t"<<b[i]<<"\t";
cout<<c[i]<<endl;
}
getch();
return 0;
}
#include<iostream.h>
#include<conio.h>
int main()
{
int a[10],d[10];
float b[10],e[10];
char c[10][10],f[10][10];
int m,n,i,j;
cout<<"Enter no of elements in List 1 & List 2";
cin>>m>>n;
cout<<"Enter Roll no, Marks & Name of List 1"<<endl;
for(i=0;i<m;i++)
{
cin>>a[i]>>b[i];
cin>>c[i];
}
cout<<"Enter Roll no, Marks & Name of List 2"<<endl;
for(j=0;j<n;j++)
{
cin>>d[j]>>e[j];
cin>>f[j];
}
//shifting
for(i=m+n;i>=n;i--)
{
a[i]=a[i-n];
b[i]=b[i-n];
strcpy(c[i],c[i-n]);
}
//merging
for(i=0;i<n;i++)
{
a[i]=d[i];
b[i]=e[i];
strcpy(c[i],f[i]);
}
//printing Table
cout<<"Roll No"<<"\t"<<"Marks"<<"\t"<<"Name"<<endl;
for(i=0;i<m+n;i++)
{
cout<<a[i]<<"\t"<<b[i]<<"\t";
cout<<c[i]<<endl;
}
getch();
return 0;
}
No comments:
Post a Comment