2D ARRAY
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int t, i;
int[,] table = new int[3, 4];
for (t = 0; t < 3; t++)
{
for (i = 0; i < 4; i++)
{
table[t, i] = (t * 4) + i + 1;
Console.WriteLine(table[t, i] + "");
}
Console.ReadLine();
}
}
}
}
/* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
* 10
* 11
* 12
*/
jagged array
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int [][] jagged = new int [3][];
jagged[0]= new int [4];
jagged[1]= new int [7];
jagged[2]= new int [2];
int i;
//store values in stored array
for(i=0;i<4;i++)
{
jagged [0][i] =i;
}
for(i=0;i<7;i++)
{
jagged [1][i] =i*i;
}
for(i=0;i<2;i++)
{
jagged [2][i] =i*i*i;
}
//display the array
for(i=0;i<4;i++)
{
Console.Write( jagged [0][i] + " ");
}
Console.WriteLine();
for(i=0;i<7;i++)
{
Console.Write(jagged [1][i] + " ");
}
Console.WriteLine();
for(i=0;i<2;i++)
{
Console.Write (jagged [2][i] + " ");
}
Console.WriteLine();
Console.ReadLine();
}
}
}
//
//0 1 2 3
//0 1 2 4 16 25 36
//0 1
No comments:
Post a Comment