代码如下——
#include<iostream>
using namespace std;
int main()
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= 5; j++)
{
if (i == 1 || i == 5 || j == 1 || j == 5)
{
cout << "*";
}
else
{
cout << " ";
}
}
cout << endl;
}
system("pause");
return 0;
}
运行如下——
下面给出练习解:
数学天赋!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include<iostream>
using namespace std;
int main()
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= 5; j++)
{
if (!(i % 2 == 0 && j % 2 == 0))
{
cout << "*";
}
else
{
cout << " ";
}
}
cout << endl;
}
system("pause");
return 0;
}
下面是星号阵列的最后一道题——
#include<iostream>
using namespace std;
int main()
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= 5; j++)
{
if (i==1||j==1||i+j==6)
{
cout << "*";
}
else if(i+j<6)
{
cout << " ";
}
}
cout << endl;
}
system("pause");
return 0;
}
运行结果如下——
以上就是星号阵列全部的例题!