{ "question_id": 348590, "question_title": "矩阵问题", "question_content": "题目描述\n编写以下函数:\n(1)在一个二维数组中形成以下形式的n阶矩阵:\n[1 1 1 1 1\n2 1 1 1 1\n3 2 1 1 1\n4 3 2 1 1\n5 4 3 2 1]\n(2)去掉靠边的元素,生成新的n-2阶矩阵;\n(3)求生成的n阶矩阵主对角线上的元素之和;\n(4)以方阵形式输出数组。\n在main函数中调用以上函数进行测试。\n输入\n输入生成矩阵的阶数(n>=2)\n输出\n以方阵形式输出生成的n阶矩阵、去掉靠边的元素生成的新的n-2阶矩阵、以及生成的n阶矩阵主对角线上的元素之和,最后一行要回车\n样例输入\n5\n样例输出\nGenerated matrix:\n1 1 1 1 1\n2 1 1 1 1\n3 2 1 1 1\n4 3 2 1 1\n5 4 3 2 1\ndel the elements on the side:\n1 1 1\n2 1 1\n3 2 1\nThe sum of the diagonal:5\n", "difficulty": "中等", "answer_id": 355486, "answer_content": "#include \n\n/* run this program using the console pauser or add your own getch, system(\"pause\") or input loop */\nusing namespace std; \nint main() {\nwhile(1){\n\n\tint a;\n\tcin>>a;//输入一个数 \n\tint array[a][a];//创建n阶数组 \n\tfor (int i=0;i= 1 ; i-- , j++)//对角 \n\t{\t\n\t\tsum+=array[i][j];//累加 \n\t}\n\tcout<<\"The sum of the diagonal:\"<\nusing namespace std; \nint main() {\n\twhile(1){\n\t\tint a;\n\t\tcin>>a;\n\t\tint array[a][a];\n\t\tfor (int i=0;i= 1 ; i-- , j++)\n\t\t{\t\n\t\t\tsum+=array[i][j];\n\t\t}\n\t\tcout<<\"The sum of the diagonal:\"<