标签:日常
1.求两个或三个正整数中的最大数,用带有默认函数的参数实现。int max_2(int x = 0,int y = 0)
{if(y > x)
x = y;
return x;
}
int main()
{int a,b,c;
cout<<"请输入三个数"<<endl;
cin>>a>>b>>c;
cout<<"max_3 = "<<max_3(a,b,c)<<endl;
cout<<"max_2 = "<<max_2(a,b)<<endl;
}
2.输入一个字符串,把其中字符串按逆序输入。用string方法。
#include<iostream>
#include<string>
using namespace std;
int mian()
{string word;
int i;
cout<<"请输入字符串"<<endl;
cin>>word;
i = strlen(word);
for(;i>=0;i--)
cout<<word[i];
cout<<endl;
return 0;
}
标签:日常
原文地址:http://blog.51cto.com/13615683/2091806