Tuesday, 20 November 2012

Array | single dimensional array in c | c# | java | using for loop

Array | single dimensional array in c | c# | java | using for loop

How to print single array value.
array similar datatype collection.
declaration | initialization


int[] arr = new int[3];
    arr[0] = 1;
    arr[1] = 2;
    arr[2] = 3;
    Response.Write(arr[2]);
ptint second  value in array;

    int[] arr = new int[]{ 1, 2, 3, };
    for (int i = 0; i < arr.Length; i++)
    {
        Response.Write(arr[i]);
        Response.Write("<br>");
    }

   
    string[] arr = new string[4]{"hi","how","are","u"};
    for (int i = 0; i < arr.Length; i++)
    {
        Response.Write(arr[i]);
        Response.Write("<br>");
    }
in place of response.write c programmers can write "printf".
in java "System.out.println". this example shows array with int and string data-type

Multidimensional Array | two dimensional array c | c# | java |2*2 | 3*3 examples code

Multidimensional Array | two dimensional array c | c# | java |2*2 | 3*3 examples code

how to use array to perform or to write or to create structure of matrix.
declaration of array using for loop ,initialization of array using for loop.
how to create 2/2 or 3/3 array in simple programming language

creation of 2/2 array which will appear like matrix.

        int[,] arr = new int[2,2]
       
                                {
                                {1, 2,3 } ,
                                {4, 5 ,6},
                               
                               
                                };
        for (int i = 0; i <2; i++)
        {
            for (int j = 0; j<2; j++)
            {
             
                Response.Write((arr[i,j]));
                             
               
            }
            Response.Write("<br>");

        }
 

creation of 3/3 array
       
        int[,] arr = new int[3,3]
                                {
                                {1, 2,3 } ,
                                {4, 5 ,6},
                                  {889, 9 ,93},
                               
                                };
        for (int i = 0; i <3; i++)
        {
            for (int j = 0; j<3; j++)
            {
             
                Response.Write((arr[i,j]));
                             
               
            }
            Response.Write("<br>");

        }
 


printing of 2/3 array using for loop.
 int[,] arr = new int[2,3]
                                {
                                {1, 2,3 } ,
                                {4, 5 ,6},
                               
                               
                                };
        for (int i = 0; i <2; i++)
        {
            for (int j = 0; j<3; j++)
            {
             
                Response.Write((arr[i,j]));
                             
               
            }
            Response.Write("<br>");

        }
response.write use in asp.net to print array so if you want to print in c language just use printf.
whereas in   java it is system.out.println