//sorting by roll no
#include<iostream.h>
#include<conio.h>
int main()
{
int a[10];
float b[10];
char c[10][10];
int m,i,j;
cout<<"Enter no of elements in List ";
cin>>m;
cout<<"Enter RollNo ,Marks and Name of List";
for(i=0;i<m;i++)
{
cin>>a[i]>>b[i];
cin>>c[i];
}
cout<<"Unsorted Array"<<endl;
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;
}
//sorting
for(i=0;i<m-1;i++)
{
for(j=0;j<m-i;j++)
{
if(a[j]>a[j+1])
{
int t1;
float t2;
char t3[10];
t1=a[j];
a[j]=a[j+1];
a[j+1]=t1;
t2=b[j];
b[j]=b[j+1];
b[j+1]=t2;
strcpy(t3,c[j]);
strcpy(c[j],c[j+1]);
strcpy(c[j+1],t3);
}
}
}
//printing Table
cout<<"Sorted By Roll No"<<endl;
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;
}
#include<iostream.h>
#include<conio.h>
int main()
{
int a[10];
float b[10];
char c[10][10];
int m,i,j;
cout<<"Enter no of elements in List ";
cin>>m;
cout<<"Enter RollNo ,Marks and Name of List";
for(i=0;i<m;i++)
{
cin>>a[i]>>b[i];
cin>>c[i];
}
cout<<"Unsorted Array"<<endl;
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;
}
//sorting
for(i=0;i<m-1;i++)
{
for(j=0;j<m-i;j++)
{
if(a[j]>a[j+1])
{
int t1;
float t2;
char t3[10];
t1=a[j];
a[j]=a[j+1];
a[j+1]=t1;
t2=b[j];
b[j]=b[j+1];
b[j+1]=t2;
strcpy(t3,c[j]);
strcpy(c[j],c[j+1]);
strcpy(c[j+1],t3);
}
}
}
//printing Table
cout<<"Sorted By Roll No"<<endl;
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