Latest Post
Showing posts with label Array. Show all posts
Showing posts with label Array. Show all posts

Array - Three Dimensional Array in C Programming

Written By Unknown on Thursday, October 10, 2013 | 7:41 AM

Three Dimensional Array :
We can work with Three Dimensional Array in C- Program.Basically Three Dimensional Arrays are array of an array.Like :
               int table [10][10][10];

If we declare any array like above than compiler will allocate memory for 10*10*10 = 1000 array elements.

Basically more than one of two Dimensional Array makes Three Dimensional Array.Watch the program below :

                                   #include<stdio.h>
                                   #include<conio.h>
                                    main()
                                    {
                                           int i,j,k;
                                           int table [3][4][2] = {
                                                                              {1,2},
                                                                              {3,4},
                                                                              {5,6},
                                                                              {7,8},
                                                                          },
                                                                          {
                                                                               {9,10},
                                                                               {11,12},
                                                                               {13,14},
                                                                               {15,16},
                                                                           },
                                                                           {
                                                                                {17,18},
                                                                                {19,20},
                                                                                {21,22},
                                                                                {23,24},
                                                                            },
                                                                            };
                                                                                for(i=0;i<3;i++)
                                                                            {
                                                                                for(j=0,j<4,j++)
                                                                            {
                                                                                for(k=0;k<2;k++)
                                                                                printf("\n array[%d][%d][%d]=",i,j,k);
                                                                            } /*End for j*/
                                                         } /*End for i*/
                                          getch();
                                       }

Run This Program To See The OUTPUT.

Program Analysis :
-> In this program,Three for loop is used through i,j,k variable.

-> table [][][2]
here a one dimensional array is working including two array element.

-> table [][4][2]
Four One Dimensional Array generated a Two Dimensional Array here.

-> table [3][4][2]
Three Two Dimensional Array generated a Three Dimensional Array here.

Array - Two Dimensional Array in C Programming

Two Dimensional Array :
Two Dimensional Array can be created in C - Program.Sometime it called "matrix".Two Dimensional Array has two subscript or index.The declaration of Two Dimensional Array is :
                 
        Data_Type Array_Name [row] [column]

Here row and column are sizes of these array.EX :
       
        int table [3][2];

The above table is a Two Dimensional Array with 3 rows and 2 columns.

Two Dimensional Array Initialization :
There are many ways to Initialize Two Dimensional Array:Like  :

                                                   int table [4][2]={
                                                                                {1,2},
                                                                                {3,4},
                                                                                {5,6},
                                                                                {7,8},
                                                                            };

We can also initialize it like this      :              int table[4][2]={1,2,3,4,5,6,7,8};

We must mention second index for initializing Two Dimensional Array:EX  :
                                                 
                                                   int table [][2]={1,2,3,4,5,6,7,8};    //correct form


Watch The program :     #include<stdio.h>
                                        #include<conio.h>
                                        #define ROLL 4
                                        #define NUM  2
                                         main()
                                         {
                                               int student [ROLL] [NUM];
                                               int p;
                                               printf("Type Roll And Marks :");
                                               for(p=0;p<=3;p++)
                                          {
                                               scanf("%d%d",&student [p][0],&student [p][1]);
                                           }
                                                for(p=0;p<=3;p++)
                                          {
                                               printf("\n%d%d",student[p][0],student[p][1]);
                                           }
                                               getch();
                                           }
INPUT :         Type Roll And Marks :
                       1
                       2
                       3
                       4
                       5
                       6
                       7
                       8

OUTPUT :       1,2
                        3,4
                        5,6
                        7,8

Hope all of you understand how Two Dimensional Array works.Thank you very much for reading.
                                                 
                 

Basic Discussion And Knowledge Building on "Array"

Array :
Array is a type of variable collector which contain more than one variable with the same name.The way to declare array is as follow :
           Data_Type Array_Name [Size]

Data_Type means what type of array we will work with ( int, char.. etc ).How many variable or element will array contain is declared by the size of array.Like :
         
           int i [5]

Here i is an int type array and this array containing 5 variable or element.Array element starts from zero(0).

              i [0]

Here, i [0] is the first element of i [5] array.


Why We Use Array :
Lets think we will have to find out 30 days temperature individually and at the end of the month we will have to find the average temperature of that month.To do this we must need 30 variables like :

                 int first_day,second_day,third_day.....

but if we do this same task for 365 days than what will we do?Can we declare 365 variables easily?I don't think so....
In this case we can use " array " to compress our program and make it quit easy.

Array Declaration :
We can declare array of any data type.Like :
                                                                 int numb[25];
                                                                 char name[55];
                                                                 float value[20];
                                                                 double price[100];

Assigning Value In Array :
Array element could be used anywhere in the program as like an ordinary variable.Ex :
                                                                 int i [5];
                                                                 i[2] = 10;
                                                                 i[1] = i[2];
Array Initialization :
When array is declared,It can also be initialized too.Like :
                                                                 int numb [5]={1,2,3,4,5};

Watch The Program Carefully :
                                                                 #include<sthio.h>
                                                                 #include<conio.h>
                                                                  main()
                                                                  {
                                                                   static char cloud [] = {'C' ,'L', 'O', 'U', 'D'}
                                                                  int i;
                                                                  for(i=0;i<5;i++)
                                                                  printf("%c",cloud[i]);
                                                                  getch();
                                                                  }

OUTPUT :   CLOUD 

CONFUSE??

CONFUSE??
 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Learn Programming - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger| Distributed by Rocking Templates