P35 T7
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
int f(int x,int y,int z);
cin>>a>>b>>c;
c=f(a,b,c);
cout<<c<<endl;
return 0;
}
int f(int x,int y,int z)
{
int m;
if(x>y)
m=x;
else m=y;
if (z>m)
m=z;
return(m);
}
T8
#include <iostream>
using namespace std;
int main()
{
int x,y;
cin>>x>>y;
if (x>y)
cout<<x<<","<<y<<endl;
else cout<<y<<","<<x<<endl;
return 0;
}
T9
#include <iostream>
using namespace std;
int main()
{
void sort(int x,int y,int z);
int x,y,z;
cin>>x>>y>>z;
sort(x,y,z);
return 0;
}
void sort(int x,int y,int z)
{
int temp;
if(x>y)
{ temp=x;x=y;y=temp;}
if (z<x) cout<<z<<","<<x<<","<<y<<endl;
else if(z<y) cout<<x<<","<<z<<","<<y<<endl;
else cout<<x<<","<<y<<","<<z<<endl;
}
T10
#include<iostream>
#include<string.h>
using namespace std;
main()
{
char a[20]="1234";
char b[]="abcd";
strcat(a,b);
cout<<a<<endl;
}
T11
#include<iostream>
#include<string>
using namespace std;
int main()
{
int i;
string str;
cout<<"请输入一串字符:"<<endl;
cin>>str;
cout<<"字符串倒序后为:"<<endl;
for(i=str.length()-1;i>=0;i--)
cout<<str[i];
cout<<endl;
system("pause");
return 0;
}
T12
#include <iostream>
#include <string>
using namespace std;
int main()
{
int i;
string str[5];
void sort(string s[]);
cout<<"Please input string:"<<endl;
for(i=0;i<5;i++)
cin>>str[i];
sort(str);
cout<<"The sorted string is:"<<endl;
for(i=0;i<=5;i++)
cout<<str[i]<<" ";
cout<<endl;
return 0;
}
void sort(string s[])
{
int i,j;
string temp;
for(i=0;i<4;i++)
for(j=0;j<4-i;j++)
if(s[j]>s[j+1])
{
temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
}
T13
#include<iostream>
using namespace std;
template <typename Type>
void sort(Type* cp);
int main()
{
int a[5]={1,9,0,23,-45};
float b[5]={2.4, 7.6, 5.5, 6.6, -2.3 };
long int c[5]={10100,-123567, 1198783,-165654, 3456};
sort(a);
sort(b);
sort(c);cin.get();
return 0;
}
template <typename Type>
void sort(Type* cp)
{
int i,j;
Type temp;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(cp[j]>cp[j+1])
{temp=cp[j];
cp[j]=cp[j+1];
cp[j+1]=temp;}
}
}
for(i=0;i<5;i++)
cout<<cp[i]<<" ";
cout<<endl;
}
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
int f(int x,int y,int z);
cin>>a>>b>>c;
c=f(a,b,c);
cout<<c<<endl;
return 0;
}
int f(int x,int y,int z)
{
int m;
if(x>y)
m=x;
else m=y;
if (z>m)
m=z;
return(m);
}
T8
#include <iostream>
using namespace std;
int main()
{
int x,y;
cin>>x>>y;
if (x>y)
cout<<x<<","<<y<<endl;
else cout<<y<<","<<x<<endl;
return 0;
}
T9
#include <iostream>
using namespace std;
int main()
{
void sort(int x,int y,int z);
int x,y,z;
cin>>x>>y>>z;
sort(x,y,z);
return 0;
}
void sort(int x,int y,int z)
{
int temp;
if(x>y)
{ temp=x;x=y;y=temp;}
if (z<x) cout<<z<<","<<x<<","<<y<<endl;
else if(z<y) cout<<x<<","<<z<<","<<y<<endl;
else cout<<x<<","<<y<<","<<z<<endl;
}
T10
#include<iostream>
#include<string.h>
using namespace std;
main()
{
char a[20]="1234";
char b[]="abcd";
strcat(a,b);
cout<<a<<endl;
}
T11
#include<iostream>
#include<string>
using namespace std;
int main()
{
int i;
string str;
cout<<"请输入一串字符:"<<endl;
cin>>str;
cout<<"字符串倒序后为:"<<endl;
for(i=str.length()-1;i>=0;i--)
cout<<str[i];
cout<<endl;
system("pause");
return 0;
}
T12
#include <iostream>
#include <string>
using namespace std;
int main()
{
int i;
string str[5];
void sort(string s[]);
cout<<"Please input string:"<<endl;
for(i=0;i<5;i++)
cin>>str[i];
sort(str);
cout<<"The sorted string is:"<<endl;
for(i=0;i<=5;i++)
cout<<str[i]<<" ";
cout<<endl;
return 0;
}
void sort(string s[])
{
int i,j;
string temp;
for(i=0;i<4;i++)
for(j=0;j<4-i;j++)
if(s[j]>s[j+1])
{
temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
}
T13
#include<iostream>
using namespace std;
template <typename Type>
void sort(Type* cp);
int main()
{
int a[5]={1,9,0,23,-45};
float b[5]={2.4, 7.6, 5.5, 6.6, -2.3 };
long int c[5]={10100,-123567, 1198783,-165654, 3456};
sort(a);
sort(b);
sort(c);cin.get();
return 0;
}
template <typename Type>
void sort(Type* cp)
{
int i,j;
Type temp;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(cp[j]>cp[j+1])
{temp=cp[j];
cp[j]=cp[j+1];
cp[j+1]=temp;}
}
}
for(i=0;i<5;i++)
cout<<cp[i]<<" ";
cout<<endl;
}