<body>


Thursday, 13 November 2008

week3
1) static void Main() { int[,] sales = new int[3, 2]; //initialise it with zeros for (int row = 0; row < 3; row++) { for (int col = 0; col < 2; col++) { sales[row, col] = 0; } } //Prompt the user to enter data into array for (int row = 0; row < 3; row++) { for (int col = 0; col < 2; col++) { Console.Write("Enter sales:$"); sales[row, col] = int.Parse(Console.ReadLine()); } } //display data using foreach loop foreach (int value in sales) { Console.WriteLine("Sales is $" + value); } for (int row = 0; row < 3; row++) { Console.WriteLine("Sales in row" + (row + 1)); for (int col = 0; col < 2; col++) { Console.WriteLine(sales[row, col]); } } }//end main }
2)static void Main() { int[,] item = new int[10, 5];
for (int row = 0; row < 10; row++) { for (int col = 0; col < 5; col++) { item[row, col] = 0; } } for (int row = 0; row < 10; row++) { for (int col = 0; col < 5; col++) { Console.Write("Enter item: "); item[row, col] = int.Parse(Console.ReadLine()); } } foreach (int value in item) { Console.WriteLine("item is" + value); } for (int row = 0; row < 10; row++) { Console.WriteLine("item in row" + (row + 1)); for (int col = 0; col < 5; col++) { Console.WriteLine(item[row, col]); } } } }}
3)static void Main() { int[,] item = new int[3, 5];
for (int vehicle = 0; vehicle < 3; vehicle++) { for (int customer = 0; customer < 5; customer++) { Console.WriteLine("enter item being delivered: "); item[vehicle, customer] = int.Parse(Console.ReadLine()); } }
foreach (int value in item) { Console.WriteLine("item is" + value); } for (int vehicle = 0; vehicle < 3; vehicle++) { Console.WriteLine("item for vehicle" + (vehicle + 1)); for (int customer = 0; customer < 5; customer++) { Console.WriteLine(item[vehicle, customer]); } }
} }}
4)static void Main() { int[,] item = new int[10, 5]; for(int row=0;row<10;row++) { for (int col = 0; col < 5; col++) { item[row, col] = 0; } }
for(int row=0; row<10; row++) { for(int col=0; col<5; col++) {
Console.WriteLine("enter item: "); item[row,col]=int.Parse(Console.ReadLine()); } }
for (int row = 0; row < 10; row++) { for (int col = 0; col < 10; col++) { item[4, 3] = 22; item[5, 4] = 30; } }
//display data using foreach loop foreach (int value in item) { Console.WriteLine("item is" + value); } for (int row = 0; row < 10; row++) { Console.WriteLine("items stored in row" + (row + 1)); for (int col = 0; col < 5; col++) { Console.WriteLine(item[row, col]); } } } }}
Q5
static void Main() { int[,] item = new int[3, 5];
for (int vehicle = 0; vehicle < 3; vehicle++) { for (int customer = 0; customer < 5; customer++) { item[vehicle,customer]=0; } }
for(int vehicle=0; vehicle<3; vehicle++) { for(int customer=0; customer<5; customer++) { Console.WriteLine("enter items being delivered: "); item[vehicle,customer]=int.Parse(Console.ReadLine()); } } for (int vehicle = 0; vehicle < 3; vehicle++) { for (int customer = 0; customer < 5; customer++) { item[0, 0] = 200; item[0, 1] = 400; } }
foreach (int value in item) { Console.WriteLine("item is" + value); } for (int vehicle = 0; vehicle < 3; vehicle++) { Console.WriteLine("items deliverd from warehouse" + (vehicle + 1)); for (int customer = 0; customer < 5; customer++) { Console.WriteLine(item[vehicle,customer]); } }
} }}

what we could have been, 6:10 pm.

Profile

Tingyi
Nanyang Polytechic
07 Sep 1988
Tagboard
Wishlist
new camera
▪ the 21th birthday
▪ GET high GPA
▪ Have a romantic love story
▪ Travel around the world
animated counter

Links
Agnes
Teresa
Pamela
Shili
Yue Ling
Cheryl
Zi Wei
Jon
Liting
Nurff
Jane
Guowei
Jack(Evil man)
Suwanno
Zaiyong
Xue ting
Alvin
Peggie
XueTing
Henry
Archives
November 2008 December 2008 January 2009 February 2009 March 2009 April 2009 May 2009 June 2009 July 2009 August 2009 September 2009 June 2010
Credits