write a prg to create a jagged arrays as follows:
3 4 2 9 0
2 5
1 6 8
also write code to print the above jagged arrays in reverse order as follows:
0 9 2 4 3
5 2
8 6 1
1
Expert's answer
2012-10-05T07:58:06-0400
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace ConsoleApplication1 { & class Program { & static void Main(string[] args) & { List<List<int>> MyArray = new List<List<int>>();
List<int> a = new List<int>(); a.Add(3); a.Add(4); a.Add(2); a.Add(9); a.Add(0); MyArray.Add(a); List<int> b = new List<int>(); b.Add(2); b.Add(5); MyArray.Add(b); List<int> c = new List<int>(); c.Add(8); c.Add(6); c.Add(1); MyArray.Add(c);
for (int i = 0; i < MyArray.Count; i++) { for (int j = 0; j < MyArray[i].Count; j++) { & Console.WriteLine(MyArray[i][j]); } Console.WriteLine("\n"); }
for (int i = 0; i < MyArray.Count; i++) MyArray[i].Reverse();
for (int i = 0; i < MyArray.Count; i++) { for (int j = 0; j < MyArray[i].Count; j++) { & Console.WriteLine(MyArray[i][j]); } Console.WriteLine("\n"); } & } } }
Comments
Leave a comment