Q:
请编程实现以下任务
输入:一个正奇数n,输出:n行表示的X字符
例如输入:5
输出:
A:
/**
Created By TeqZ
2022/12/2
*/
#include<iostream>
using namespace std;
int main()
{
loop:
cout<<"Please enter a positive odd number"<<endl;
int x;
cin>>x;
if(x % 2 !=0 && x>=0)
{
int k=x;
for(int i=1; i<=x; i++)//Lines
{
for(int j=1; j<=x; j++)//Letters and Spaces
{
if(j==i||j==k) {cout<<"X";} else{cout<<" ";}
}
k--;
cout<<endl;
}
cout<<"Success! TRY another one?"<<endl<<endl;
goto loop;
}else{
cout<<"TRY AGAIN!"<<endl<<endl;
goto loop;
}
return 0;
}
Running: