//C#控制台程序
static void Main(string[] args)
{
//Console.Write()
//输入一个数
bool ifNum = false;
string n_str = "";
int n = 0;
while (!ifNum)
{
n_str = Console.ReadLine();
try
{
n = int.Parse(n_str);
ifNum = true;
}
catch (FormatException)
{
ifNum = false;
}
}
//打印
char ch = 'A';
if (n != 0)
{
//打上面的三角形
for (int i = 0; i < n + 1; i++)
{
for (int j = 0; j < n - i; j++)
{
Console.Write(' ');
}
for (int j = 0; j < 2 * i + 1; j++)
{
Console.Write(ch);
ch++;
if (ch > 'Z')
{
ch = 'A';
}
}
Console.WriteLine();
}
//打下面的三角形
for (int i = n - 1; i > -1; i--)
{
for (int j = 0; j < n - i; j++)
{
Console.Write(' ');
}
for (int j = 0; j < 2 * i + 1; j++)
{
Console.Write(ch);
ch++;
if (ch > 'Z')
{
ch = 'A';
}
}
Console.WriteLine();
}
}
Console.ReadLine();
}
有问题再问
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace cx2
{
class Program
{
static void Main(string[] args)
{
string d;
int n;
Console.Write("请输入数字: ");
d = Console.ReadLine();
try
{
n = Int32.Parse(d);
if (n < 0)
{
return;
}
else
{
if (n == 4)
{
char[,] ay = new char[9, 9];
int i = 65;
int x, y, j, k, m;
j = ay.GetLength(1) / 2;
char s = '\0';
k = m = 1;
for (x = 0; x < ay.GetLength(0); x++, k = (x < ay.GetLength(0) / 2 + 1) ? k += 2 : k -= 2, j = (x <= ay.GetLength(0) / 2) ? j -= 1 : j += 1)
{
for (y = 0, m = k; y < ay.GetLength(1) - 1; )
{
if (y != j)
{
ay[x, y] = s;
Console.Write(ay[x, y]);
y++;
}
else
{
while (m > 0)
{
if (i < 91) { ay[x, y] = (char)i; }
else { i = 65; ay[x, y] = (char)i; }
Console.Write(ay[x, y]);
i++;
m--; y++;
}
}
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
catch (Exception ex)
{
Console.WriteLine("输入有错,{0}", ex.Message);
Console.ReadLine();
}
}
}
}
同学,我要求的语言是C#不是C++
...A BCD EFGHI JKLMNOP QRSTUVWXY ZABCDEF GHIJK LMN O
\/\/C#控制台程序 static void Main(string[] args){ \/\/Console.Write()\/\/输入一个数 bool ifNum = false;string n_str = "";int n = 0;while (!ifNum){ n_str = Console.ReadLine();try { n = int.Parse(n_str);ifNum = true;} catch (FormatException){ ifNum = false;} }...
用C++如何编写一个直角三角形图案:A BCD EFGHI JKLMNOP QRSTUVWXY
void main() { int i,j,k;for ( i=0,k=0;i<N;i++ ) { for ( j=0;j<i*2+1;j++,k++ ) cout<<(char)('A'+k);cout<<endl;} }
编程输出如下图形 A BCD
(j>=line-1-i)?printf("%c",origin++):printf(" ");printf("\\n");} }
输出字母三角形
同楼上疑问。下面假设字母用光了,仍用ASCII码输出:include <stdio.h> void main(){ char start;int h;int iLoop,jLoop;printf("请输入首字母: \\t");scanf("%c",&start);printf("\\n请输入高度: \\t");scanf("%d",&h);for(iLoop=0; iLoop<h; iLoop++){ for(jLoop=0; jLoop<2...