说去下面数列的规律,并编程实现:

1

23

312

1231

23123

312312

1231231

大体想了下,应该会有更简洁的算法:

 

代码
public static void Main(string[] args)
        {
            
int a=1;
            
int b=1;
            
            
for(int i=1; i<=7; i++)
            {
                
if(b>3)
                {
                    b
=1;
                }
                a
=b;
                
                
for(int j=1; j<=i; j++)
                {
                    
                    
if(a>3)
                    {
                        a
=1;
                    }
                    Console.Write(a);
                    a
++;
                }
                
                b
++;
                Console.WriteLine();
            }
            Console.WriteLine(
"Press any key to continue...");
            Console.ReadKey(
true);
        }

 

 

相关文章:

  • 2021-12-21
  • 2021-08-20
  • 2022-01-04
  • 2021-07-09
  • 2022-01-26
  • 2021-07-05
  • 2021-12-28
  • 2022-02-25
猜你喜欢
  • 2021-05-16
  • 2021-12-21
  • 2021-09-11
  • 2022-01-13
  • 2021-10-26
  • 2021-11-18
  • 2021-11-18
相关资源
相似解决方案