for文を使用して九九表を作成出来たのですが
このコードと同じ結果をforeach文のみを使用して出力させるには
どうすればいいのでしょうか。
書籍やネットで調べてみたのですが解決できませんでした。
C#
1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Text; 5using System.Threading.Tasks; 6 7namespace ConsoleApp 8{ 9 class Program 10 { 11 static void Main(string[] args) 12 { 13 //1の段から9の段へ表示 14 Console.WriteLine("九九表"); 15 for (int x = 1; x <= 9; ++x) 16 { 17 for (int y = 1; y <= 9; ++y) 18 { 19 string s = string.Format(" {0}×{1}={2,2}", x, y, x * y); 20 21 Console.Write((s).ToString().PadLeft(3, ' ')); 22 } 23 Console.WriteLine("\n"); 24 25 } 26 Console.WriteLine("九九表"); 27 for (int x = 9; x >= 1; --x) 28 { 29 for (int y = 9; y >= 1; --y) 30 { 31 string s = string.Format(" {0}×{1}={2,2}", x, y, x * y); 32 Console.Write((s).ToString().PadLeft(3, ' ')); 33 } 34 Console.WriteLine("\n"); 35 } 36 } 37 } 38}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/17 02:07