第七题
#include<iostream>
using namespace std;
int main()
{
int max (int x =10, int y =30);
max();
cout << " max = " << max() << endl;
return 0;
}
int max ( int x, int y)
{
if (x>y) return x;
else return y;
}
<img src="https://img-blog.csdn.net/20150407125621563?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbG9uZ3hpdWh1YQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
<pre name="code" class="cpp">第八题
#include<iostream>
using namespace std;
int max( int &a, int &b)
{
if(a > b)
cout << a << " "<< b << endl;
else
cout << b << " "<< a << endl;
return 0;
}
int main()
{
int i , j;
cin >> i >> j;
max( i , j );
return 0;
}
<pre name="code" class="cpp">第九题
#include<iostream>
using namespace std;
int paixu( int &a, int &b, int &c)
{
if( a < b)
{
if( b < c)
{
cout << "a < b < c" << endl;
}
else if ( a < c )
{
cout << "a < c < b" << endl;
}
else
{
cout << "c < a < b" << endl;
}
}
else if ( b > c )
{
cout << " c < b < a " << endl;
}
else if ( a > c)
{
cout << " b < a < c " << endl;
}
else
{
cout << " b < c < a " << endl;
}
return 0;
}
int main()
{
int i , j ,k;
cout << "a = ";
cin >> i;
cout << "b = ";
cin >> j;
cout << "c =" ;
cin >> k;
paixu (i, j, k);
return 0;
}
第十题
#include<iostream>
#include<string>
using namespace std;
int main()
{
string a = "abc";
string b = "cba";
a = a + b;
cout << " a = " << a << endl;
return 0;
}
第十一题
#include<iostream>
#include<string>
using namespace std;
int main()
{
string word;
cout << "请输入字符串: " ;
cin >> word;
int i;
cout <<"倒序的字符串是: ";
for ( i = word.length(); i > 0 || i== 0; i--)
cout << word[i];
cout << endl;
return 0;
}
第十二题
#include<iostream>
#include<string>
using namespace std;
void jixupaixu(string a[])
{
int i, j ;
string temp;
for(i = 0; i < 4; i++)
{
for(j = 0; j < 4-i; j++)
{
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
}
int main()
{
string a[5];
int i;
for(i = 0; i < 5; i++)
{
cin >> a[i];
}
jixupaixu(a);
for(i = 0; i < 5; i++)
{
cout << a[i] << " ";
}
return 0 ;
}
第十三题
#include<iostream>
using namespace std;
int paixu( int *a )
{
int i , j , t;
for(i = 0; i < 10; i++ )
{
for( j = 0; j < 10 - i; j++ )
{
if( a[j] > a[j+1])
{
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
return 0;
}
float paixu( float *a )
{
int i , j , t;
for(i = 0; i < 10; i++ )
{
for( j = 0; j < 10 - i; j++ )
{
if( a[j] > a[j+1])
{
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
return 0;
}
double paixu( double *a )
{
int i , j , t;
for(i = 0; i < 10; i++ )
{
for( j = 0; j < 10 - i; j++ )
{
if( a[j] > a[j+1])
{
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
return 0;
}
int main()
{
int a[10] = {1, 5 ,9 ,99, 567, 2, 213, 921,542,42};
float b[10] = { 1.1, 22.1, 9.9, 55.1, 6.02, 66.1, 22.2, 44.9, 489.14, 1.2365};
double c[10] = {1,2,3,4,5,6,7,9,18,40};
int i;
paixu(a);
{
for (i = 0; i<10; i++)
{
cout << a[i] << " " ;
}
cout << endl;
}
paixu(b);
{
for (i = 0; i<10; i++)
{
cout << b[i] <<" ";
}
cout << endl;
}
paixu(c);
{
for (i = 0; i<10; i++)
{
cout << c[i] <<" ";
}
cout << endl;
}
return 0;
}
<img src="https://img-blog.csdn.net/20150407130612598?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbG9uZ3hpdWh1YQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /><pre name="code" class="cpp">第十四题
#include<iostream>
using namespace std;
template <typename T>
T paixu(T*a)
{
int i, j, t;
for(i = 0 ; i < 5 ; i++)
{
for (j = 0 ; j < 5-i; j++ )
{
if( a[j] > a[j+1])
{
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
return 0;
}
int main()
{
int a[5] = {1,5,2,3,4};
float b[5] = {1.9, 2.2,3.3,4.4,5.5};
double c[5] = {1.11,2.22,3.33,4.54,9.11};
int i = 0;
paixu(a);
{
for(i = 0 ; i < 5; i++)
{
cout << a[i] << " ";
}
cout << endl;
}
paixu(b);
{
for(i = 0 ; i < 5; i++)
{
cout << b[i] << " ";
}
cout << endl;
}
paixu(c);
{
for(i = 0 ; i < 5; i++)
{
cout << c[i] << " ";
}
cout << endl;
}
return 0;
}<img src="https://img-blog.csdn.net/20150407130724795?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbG9uZ3hpdWh1YQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />