Format Print N*M
Print N*M like following:
1 /*
2 * Created by SharpDevelop.
3 * User: Administrator
4 * Date: 2010-3-25
5 * Time: 22:33
6 *
7 * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 */
9 using System;
10
11 namespace MNPrint
12 {
13 class Program
14 {
15 public static void Main(string[] args)
16 {
17 int n = 10;
18 int m = 5;
19 MNPrint(n, m);
20 Console.ReadKey(true);
21 }
22
23 public static void MNPrint(int n, int m)
24 {
25 if (m < 0 || n < 0)
26 throw new ArgumentOutOfRangeException();
27
28 try
29 {
30 if (m * n > int.MaxValue)
31 throw new OverflowException();
32 }
33 catch (OverflowException ex)
34 {
35 throw ex;
36 }
37
38 for (int i = 0; i < n; i++)
39 {
40
41 if (i % 2 == 0)
42 {
43 for (int j = 1; j <= m; j++)
44 Print(i * m + j);
45 }
46 else
47 {
48 for (int j = 0; j < m; j++)
49 Print((i + 1) * m - j);
50 }
51 Console.WriteLine();
52 }
53 }
54 public static void Print(int n)
55 {
56 Console.Write(n.ToString());
57 Console.Write(";");
58 }
59 }
60 }
2 * Created by SharpDevelop.
3 * User: Administrator
4 * Date: 2010-3-25
5 * Time: 22:33
6 *
7 * To change this template use Tools | Options | Coding | Edit Standard Headers.
8 */
9 using System;
10
11 namespace MNPrint
12 {
13 class Program
14 {
15 public static void Main(string[] args)
16 {
17 int n = 10;
18 int m = 5;
19 MNPrint(n, m);
20 Console.ReadKey(true);
21 }
22
23 public static void MNPrint(int n, int m)
24 {
25 if (m < 0 || n < 0)
26 throw new ArgumentOutOfRangeException();
27
28 try
29 {
30 if (m * n > int.MaxValue)
31 throw new OverflowException();
32 }
33 catch (OverflowException ex)
34 {
35 throw ex;
36 }
37
38 for (int i = 0; i < n; i++)
39 {
40
41 if (i % 2 == 0)
42 {
43 for (int j = 1; j <= m; j++)
44 Print(i * m + j);
45 }
46 else
47 {
48 for (int j = 0; j < m; j++)
49 Print((i + 1) * m - j);
50 }
51 Console.WriteLine();
52 }
53 }
54 public static void Print(int n)
55 {
56 Console.Write(n.ToString());
57 Console.Write(";");
58 }
59 }
60 }