c++第六次作业

来源:互联网 发布:keil软件调试程序 编辑:程序博客网 时间:2024/06/12 13:41

1.矩阵求和

#include <iostream>using namespace std;int main(){    int a[3][3],i,j,a;    cout<<"输入矩阵的数值:";    for(j=0;j<3;j++)    for(i=0;i<3;i++)    {        cin>>a[j][i];    }    a=a[0][0]+a[1][1]+a[2][2]+a[0][2]+a[2][0];    cout<<"两条对角线上的元素之和:"<<a<<endl;     return 0;}

二. 字符串操作

 #include<iostream>      #include <string>    using namespace std;      int main()    {        string c;        string d ;       cout<<"字符串:c为:";        cin>>c;        cout<<"字符串:d为:";        cin>>d;        if(c==d)            cout<<"c,d两个字符串相等"<<endl;        else       cout<<"字符串c与d连接起来:"<<c+d<<endl;            cout<<"c,d两个字符串不相等"<<endl;                return 0;      }  


0 0