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

C++第六次上机作业

2016-05-19 09:40 411 查看
【项目3:矩阵求和】

#include<iostream.h>
int main()
{
int A[3][3],B,i,j;
cout<<"请按数组元素排列顺序输入矩阵:"<<endl;
for (i=0;i<3;i++)
{
for (j=0;j<3;j++)
{
cin>>A[i][j];
}
}
B=A[0][0]+A[0][2]+A[1][1]+A[2][0]+A[2][2];
cout<<"矩阵两条对角线上元素之和是:"<<B<<endl;
}


【项目5:字符串操作】

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char x[50],y[50];
cout<<"请输入50位以内的字符串x:"<<endl;
cin.getline(x,50);
cout<<"请输入50位以内的字符串y:"<<endl;
cin.getline(y,50);
if(strcmp(x,y)!=0)
cout<<"字符串x和字符串y不相等"<<endl;
else
cout<<"字符串x和字符串y相等"<<endl;
strcat(x,y);
cout<<x<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: