欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#随机数生成字母金字塔

程序员文章站 2023-12-14 19:51:34
本文实例为大家分享了c#随机数生成字母金字塔的具体代码,供大家参考,具体内容如下 1. 代码实现: static void main(string[] args...

本文实例为大家分享了c#随机数生成字母金字塔的具体代码,供大家参考,具体内容如下

1. 代码实现:

static void main(string[] args)
    {  
      shownpoint(25);
      console.readkey();
    }

    private static void shownpoint(int count)
    {
      random r = new random();

      string[] stre = { "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};

      for (int i = 1; i <=count; i++)
      {
        for (int j = 1; j <=count-i; j++)
        {
          console.write(" ");
        }

        for (int k = 1; k <= 2*i-1; k++)
        {
          console.write(stre[r.next(0,25)]);
        }
        console.writeline();
      }
    }

2. 运行结果:

C#随机数生成字母金字塔

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:

下一篇: