Use the do-while loops in nested form and produces the following output in C#
Multiple Tables
1 2 3
2 4 6
3 6 9
Solution :
First Way
Multiple Tables
1 2 3
2 4 6
3 6 9
Solution :
First Way
public static void SampleMethod() { int i = 1; int k = 1; do { int j = 1; do { Console.Write(j * k + " "); j++; } while (j <= 3); Console.WriteLine(); k++; i++; } while (i <= 3); }
Second Way :
public static void SampleMethod() { int k = 1; for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { Console.Write(j * k + " "); } Console.WriteLine(); k++; } }
0 comments:
Post a Comment