您的位置:首页 > 编程语言 > C语言/C++

c++第六次实验

2016-05-27 20:59 387 查看
二.字符串操作
[cpp] view plain copy 在CODE上查看代码片派生到我的代码片
<pre name="code" class="cpp">#include<iostream>
#include <string>
using namespace std;
int main()
{
string a;
string b;
cout<<"请输入字符串:a=";
cin>>a;
cout<<"请输入字符串:b=";
cin>>b;
if(a==b)
cout<<"两个字符串相等"<<endl;
else
cout<<"两个字符串不相等"<<endl;
cout<<"字符串ab为"<<a+b<<endl;
return 0;
}


#include<iostream>
using namespace std;
int main()
{
int a[5]={1,3,8,9,10},b[5]={2,3,4,5,6},c[10],i,j,t;
for(i=0; i<5; i++)
{
c[i] = a[i];
}
for(i=5; i<10; i++)
{
c[i] = b[i-5];
}
for(i=0; i<9; i++)
for(j=0; j<9-i;j++)
{
if(c[j] > c[j+1])
{
t = c[j];
c[j] = c[j+1];
c[j+1] = t;
}
}
cout<<"数组a为a[5]=1 3 8 9 10"<<endl;
cout<<"数组b为b[5]=2 3 4 5 6"<<endl;
cout<<"数组c为:";
for(i=0; i<10; i++)
{
cout<<c[i]<<" ";
}
cout<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: