已知一个n*n(n<=100)的矩阵,把矩阵的主、次两条对角线的每个元素值加上x(运算保证在int范围内),然后输出矩阵。
废话不多说,上代码!
输入: 输出:
3 4 5 2 7
1 2 3 1 6 3
1 2 3 5 2 7
1 2 3
#include<bits/stdc++.h>
using namespace std;
int main(){
bool check;
for (int x=100;x<=200;x++){
check=true;
for (int i=2;i<x-1;i++) {
if (x%i==0) {
check=false;
break;
}
}
if (check) cout<<x<<" ";
}
return 0;
}