Visual Studio-C#-20160417-列印星星,迭代窮舉

來源:互聯網
上載者:User

標籤:

static void Main22(string[] args)
{
//菱形
Console.WriteLine("請輸入腰長:");
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i <n; i++)
{
for (int j = 0; j <n-i; j++)
{
Console.Write(" ");
}
for (int k =0; k <2*i-1; k++)
{
Console.Write("★");
}
Console.Write("\n");
}
for (int l = 0; l <=n; l++)
{
for (int m = 0; m <l; m++)
{
Console.Write(" ");
}
for (int o = 2*n-1; o >2*l; o--)
{
Console.Write("★");
}
Console.Write("\n");
}
}


static void Main14(string[] args)
{
//右上等腰直角三角形
Console.WriteLine("請輸入腰長:");
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i <=n; i++)
{
for (int k = 0; k < i; k++)
{
Console.Write(" ");
}
for (int j = n; j > i; j--)
{
Console.Write("★");
}
Console.Write("\n");
}
}


static void Main13(string[] args)
{
//右下等腰直角三角形
Console.WriteLine("請輸入腰長:");
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i<n; i++)
{
for (int k = 1; k <n-i; k++)
{
Console.Write(" ");
}
for (int j = 0; j <=i; j++)
{
Console.Write("★");
}
Console.Write("\n");
}
}


static void Main12(string[] args)
{
//左上等腰直角三角形
Console.WriteLine("請輸入腰長:");
int n = Convert.ToInt32(Console.ReadLine());
for (int i = n; i >=0; i--)
{
for (int j = 0; j < i; j++)
{
Console.Write("★");
}
Console.Write("\n");
}
}


static void Main11(string[] args)
{
//左下等腰直角三角形
Console.WriteLine("請輸入腰長:");
int n = Convert.ToInt32(Console .ReadLine());
for (int i = 0; i <= n; i++)
{
for (int j = 0; j < i; j++)
{
Console.Write("★");
}
Console.Write("\n");
}
}

#region*****迴圈練習*****
static void Main5(string[] args)
{
int j = 1;
for (int i = 6; i >0; i--)
{
j = j*i;
}
Console.Write(j);
}


static void Main4(string[] args)
{
for (int i = 1; i < 100; i++)
{
if (i%7==0||i%10==7||i/10==7)
Console.Write("{0} ",i);
}
}

 

static void Main3(string[] args)
{
for (int i = 0; i < 128; i++)
{
Console.Write((char)i+"={0} ",i);
}
}


static void Main2(string[] args)
{
for (int i = 1; i < 51; i++)
{
int j = 2 * i - 1;
Console.Write("{0} ",j);
}
}


static void Main1(string[] args)
{
Console.Write("這是一個");
for (int i = 1; i <= 100; i++)
{
Console.Write("非常");
}
Console.Write("長的句子");
}
#endregion

 

//斐波那契數列
static void Main(string[] args)
{
int b=1;
int c=0;
int d=0;
for (int a = 1; a < 24; a++)
{
d = b + c;
b = c;
c = d;
Console.Write("{0} ",d);
}
}

 

//猴子吃桃子
static void Main32(string[] args)
{
int b=1;
for (int a = 1; a < 7; a++)
{
b = (b + 1) * 2;
}
Console.Write("原有{0}個桃子", b);
}

 


static void Main31(string[] args)
{
for (int a = 0; a <= 20; a++)
{
for (int b = 0; b <= 50; b++)
{
for (int c = 0; c <= 7; c++)
{
if (5 * a + 2 * b + 15 * c == 100)
Console.WriteLine("購買{0}支牙刷,{1}塊肥皂,{2}瓶洗髮水",a,b,c);
}
}
}
}

 

static void Main1111111111111(string[] args)
{

//100以內的質數
for (int i = 2; i < 100; i++)
{
bool a = true;
for (int j = 2; j <=Math .Sqrt( i); j++)
{
if (i % j == 0)
{
a=false;
break;
}
}
if (a)
Console.Write("{0} ", i);
}
}

Visual Studio-C#-20160417-列印星星,迭代窮舉

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.