1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C#の練習(九九表)

Posted at

##九九表を表示する
今回はC#の練習のために九九表を表示するプログラムを制作しました
##ソースコード


using System;
class WhileSample
{
static void Main()
{
int val;
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= 9; j++)
{
val = i * j;
System.Console.Write("{0,3}", val.ToString() + " ");
}
System.Console.Write("\n");
} Console.ReadKey();
}
}

##結果九九.PNG
##まとめ
ijを内側のfor文で回して初めは11から12になってjが9になったら一度中のfor文を終わらせて外のfor文を回して21...2*2と同じように回していきます。
表示する文のSystem.Console.Write("{0,3}", val.ToString() + " ");中の**{0,3}**を使うことで計算結果の表示スペースを広く確保することで桁の違いによる表のずれをなくしました
1
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?