1.7 #include<iostream>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b;
int max(int a,int b,int c=5);
cout<<"max(a,b,c)="<<max(a,b)<<endl;
return 0;
}
int max(int a,int b,int c=5)
{
if(a<b)
a=b;
if(a<c)
a=c;
return a;
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b;
int max(int a,int b,int c=5);
cout<<"max(a,b,c)="<<max(a,b)<<endl;
return 0;
}
int max(int a,int b,int c=5)
{
if(a<b)
a=b;
if(a<c)
a=c;
return a;
}
1.8 #include<iostream>
using namespace std;
int max(int &x,int &y)
{
if(x<y)
x=y;
return x;
}
int main()
{
int a,b;
cin>>a>>b;
cout<<"max(a,b)="<<max(a,b)<<endl;
return 0;
}
1.9
#include<iostream>
using namespace std;
float sort(float &x,float &y,float &z)
{
float t;
if(x>y)
{t=x; x=y; y=t;}
if(x>z)
{t=x;x=z;z=t;}
if(y>z)
{t=y;y=z;z=t;}
cout<<x<<y<<z<<endl;
return 0;
}
int main()
{
float a,b,c;
cin>>a>>b>>c;
sort(a,b,c);
return 0;
}
using namespace std;
float sort(float &x,float &y,float &z)
{
float t;
if(x>y)
{t=x; x=y; y=t;}
if(x>z)
{t=x;x=z;z=t;}
if(y>z)
{t=y;y=z;z=t;}
cout<<x<<y<<z<<endl;
return 0;
}
int main()
{
float a,b,c;
cin>>a>>b>>c;
sort(a,b,c);
return 0;
}
1.10 #include<iostream>
#include<string>
using namespace std;
int main()
{
string str1,str2;
cin>>str1>>str2;
str1=str1+str2;
cout<<str1;
return 0;
}
#include<string>
using namespace std;
int main()
{
string str1,str2;
cin>>str1>>str2;
str1=str1+str2;
cout<<str1;
return 0;
}
1.11 #include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
cin>>str;
int i,j;
int length=sizeof(str);
for(i=length-1;i>=0;i--)
{
cout<<str[i];
}
return 0;
}
#include<string>
using namespace std;
int main()
{
string str;
cin>>str;
int i,j;
int length=sizeof(str);
for(i=length-1;i>=0;i--)
{
cout<<str[i];
}
return 0;
}
1.12 #include<iostream>
#include<string>
using namespace std;
void bubble_sort(string a[],int n)
{
int i,j;
string temb;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]>=a[j-1])
{
temb=a[j];
a[j]=a[j-1];
a[j-1]=temb;
}
}
}
}
int main()
{
int n;
string str[5];
for(n=0;n<5;n++)
{
cin>>str[n];
}
bubble_sort(str,5);
for(n=0;n>5;n++)
{
cout<<str[n];
}
return 0;
}
#include<string>
using namespace std;
void bubble_sort(string a[],int n)
{
int i,j;
string temb;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]>=a[j-1])
{
temb=a[j];
a[j]=a[j-1];
a[j-1]=temb;
}
}
}
}
int main()
{
int n;
string str[5];
for(n=0;n<5;n++)
{
cin>>str[n];
}
bubble_sort(str,5);
for(n=0;n>5;n++)
{
cout<<str[n];
}
return 0;
}
1.13 #include <iostream>
#include <string>
using namespace std;
int main( )
{
longa[5]={10100,-123567, 1198783,-165654, 3456};
intb[5]={1,9,0,23,-45};
floatc[5]={2.4, 7.6, 5.5, 6.6, -2.3 };
voidsort(long [ ]);
void sort(int [ ]);
voidsort(float [ ]);
sort(a);
sort(b);
sort(c);
return 0;
}
void sort(long a[ ])
{
#include <string>
using namespace std;
int main( )
{
longa[5]={10100,-123567, 1198783,-165654, 3456};
intb[5]={1,9,0,23,-45};
floatc[5]={2.4, 7.6, 5.5, 6.6, -2.3 };
voidsort(long [ ]);
void sort(int [ ]);
voidsort(float [ ]);
sort(a);
sort(b);
sort(c);
return 0;
}
void sort(long a[ ])
{
int i, j;
long t;
for (j=0;j<5; j++)
for(i=0;i<5-j;i++)
if(a[i]>a[i+1])
{t=a[i];a[i]=a[i+1];a[i+1]=t;}
cout<<"the sorted numbers : "<<endl;
for(i=0;i<5;i++)
cout<<a[i]<< " ";
cout<<endl<<endl;
}
long t;
for (j=0;j<5; j++)
for(i=0;i<5-j;i++)
if(a[i]>a[i+1])
{t=a[i];a[i]=a[i+1];a[i+1]=t;}
cout<<"the sorted numbers : "<<endl;
for(i=0;i<5;i++)
cout<<a[i]<< " ";
cout<<endl<<endl;
}
1.14 #include <iostream>
#include <string>
using namespace std;
int main( )
{ long a[5]= {10100,-123567, 1198783,-165654, 3456};
int b[5]={1,9,0,23,-45};
floatc[5]={2.4, 7.6, 5.5, 6.6, -2.3 };
voidsort(int [ ]);
voidsort(float [ ]);
voidsort(long [ ]);
sort(a); //对长整型数据排序
sort(b); //对整型数据排序
sort(c); //对单精度型数据排序
return 0;
}
void sort(long a[ ]) //对长整型数据用选择法排序的函数
{int i,j,min;
long t;
for(i=0;i<5;i++)
{min=i;
for(j=i+1;j<5;j++)
if(a[min]>a[j]) min=j;
{t=a[i]; a[i]=a[min]; a[min]=t; }
cout<<"the sorted numbers : "<<endl;
for(i=0;i<5;i++)
cout<<a[i]<<" ";
cout<<endl<<endl;
}
void sort(int a[ ]) //对整型数据用选择法排序的函数
{int i, j, t;
for (j=0;j<5; j++)
for(i=0;i<5-j;i++)
if(a[i]>a[i+1])
{t=a[i];a[i]=a[i+1];a[i+1]=t;}
cout<<"the sorted numbers : "<<endl;
for(i=0;i<5;i++)
cout<<a[i]<< " ";
cout<<endl<<endl;
}
void sort(float a[ ]) //对单精度型数据用起泡法排序的函数
{int i, j;
float t;
for(j=0;j<5;j++)
for(i=0;i<5-j;i++)
if(a[i]>a[i+1])
{t=a[i];a[i]=a[i+1];a[i+1]=t;}
cout<<"the sorted numbers : "<<endl;
for(i=0;i<5;i++)
cout<<a[i]<< " ";
cout<<endl<<endl;
}
#include <string>
using namespace std;
int main( )
{ long a[5]= {10100,-123567, 1198783,-165654, 3456};
int b[5]={1,9,0,23,-45};
floatc[5]={2.4, 7.6, 5.5, 6.6, -2.3 };
voidsort(int [ ]);
voidsort(float [ ]);
voidsort(long [ ]);
sort(a); //对长整型数据排序
sort(b); //对整型数据排序
sort(c); //对单精度型数据排序
return 0;
}
void sort(long a[ ]) //对长整型数据用选择法排序的函数
{int i,j,min;
long t;
for(i=0;i<5;i++)
{min=i;
for(j=i+1;j<5;j++)
if(a[min]>a[j]) min=j;
{t=a[i]; a[i]=a[min]; a[min]=t; }
cout<<"the sorted numbers : "<<endl;
for(i=0;i<5;i++)
cout<<a[i]<<" ";
cout<<endl<<endl;
}
void sort(int a[ ]) //对整型数据用选择法排序的函数
{int i, j, t;
for (j=0;j<5; j++)
for(i=0;i<5-j;i++)
if(a[i]>a[i+1])
{t=a[i];a[i]=a[i+1];a[i+1]=t;}
cout<<"the sorted numbers : "<<endl;
for(i=0;i<5;i++)
cout<<a[i]<< " ";
cout<<endl<<endl;
}
void sort(float a[ ]) //对单精度型数据用起泡法排序的函数
{int i, j;
float t;
for(j=0;j<5;j++)
for(i=0;i<5-j;i++)
if(a[i]>a[i+1])
{t=a[i];a[i]=a[i+1];a[i+1]=t;}
cout<<"the sorted numbers : "<<endl;
for(i=0;i<5;i++)
cout<<a[i]<< " ";
cout<<endl<<endl;
}