一、问题及代码
字符串操作
#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 << "字符串相等";
else
cout << "字符串不相等";
cout << "则字符串ab为" << a + b;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
cout<<"输入矩阵(3*3)元素:"<<endl;
int a[3][3],i,j,sum1=0,sum2=0;
for(i=0; i<3; i++)
for(j=0; j<3; j++)
cin>>a[i][j];
cout<<"此矩阵为:"<<endl;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cout<<a[i][j]<<" ";
if(j==2)
cout<<endl;
}
}
for(i=0; i<3; i++)
for(j=0; j<3; j++)
{
if(i==j)
sum1=sum1+a[i][j];
if(i+j==2)
sum2=sum2+a[i][j];
}
cout<<"左对角线和:"<<sum1<<" 右对角线和:"<<sum2<<endl;
return 0;
}