Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Three Dimensional Array in C language

Posted on December 12, 2016January 29, 2020

Table of Contents

  • Three dimensional Array in C language
      • Knowledge Area
    • Declare a three-dimensional array
    • Initializing – using standard method
    • Initializing during the array declaration
    • Initializing and displaying using loops

Three dimensional Array in C language

In this tutorial, we will discuss the Three Dimensional Array in C language

Knowledge Area

  • What is Array
  • Type of Arrays
  • Declaration of 3 dimensional Array
  • 3 dimensional Array Initialization
  • 3 dimensional Array processing
 

In the C Programming Language, an array is a fixed sequenced collection of the element of the same data types. an array can be used to represent a list of number(int) or name (string) or other data type of similar elements. It is one of the ways of simply a grouping of similar types of data of single variables names.

Three types of arrays in C programming language

1. One dimensional array
2. Two-dimensional array
3. multidimensional array

Three dimensional Array

now we will understand the three-dimensional Array in C. C programming supports multidimensional Array. The Multidimensional array is also called a matrix

Here we will learn how to declare, initialize and access the multidimensional array

" #include <stdlib.h> int main() { int marks[2][2][3];//3 D Array declaration //initializing element marks[0][0][0]=68; marks[0][0][1]=78; marks[0][0][2]=76; marks[0][1][0]=89; marks[0][1][1]=84; marks[0][1][2]=47; marks[1][0][0]=65; marks[1][0][1]=24; marks[1][0][2]=45; marks[1][1][0]=54; marks[1][1][1]=72; marks[1][1][2]=35; //display array element based in index printf(

Declare a three-dimensional array

Syntax

data_type array_name[size1][size2][size3];

 

Example

int marks[2][3][4];

Initializing – using standard method

Program 1

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int marks[2][2][3];//3 D Array declaration
//initializing element
    marks[0][0][0]=68;
    marks[0][0][1]=78;
    marks[0][0][2]=76;
    marks[0][1][0]=89;
    marks[0][1][1]=84;
    marks[0][1][2]=47;
    marks[1][0][0]=65;
    marks[1][0][1]=24;
    marks[1][0][2]=45;
    marks[1][1][0]=54;
    marks[1][1][1]=72;
    marks[1][1][2]=35;

    //display array element based in index
    printf("Here, display array elements\n\n");
    printf("marks[0][0][0] value is: %d\n",marks[0][0][0]);
    printf("marks[0][0][1] value is: %d\n",marks[0][0][1]);
    printf("marks[0][0][2] value is: %d\n",marks[0][0][2]);
    printf("marks[0][1][0] value is: %d\n",marks[0][1][0]);
    printf("marks[0][1][1] value is: %d\n",marks[0][1][1]);
    printf("marks[0][1][2] value is: %d\n",marks[0][1][2]);
    printf("marks[1][0][0] value is: %d\n",marks[1][0][0]);
    printf("marks[1][0][1] value is: %d\n",marks[1][0][1]);
    printf("marks[1][0][2] value is: %d\n",marks[1][0][2]);
    printf("marks[1][1][0] value is: %d\n",marks[1][1][0]);
    printf("marks[1][1][1] value is: %d\n",marks[1][1][1]);
    printf("marks[1][1][2] value is: %d\n",marks[1][1][2]);
    getch();
    return 0;
}

Wen the above code is executed,it produces te following result

" #include <stdlib.h> int main() {     int array[3][4][2]={{{2,4},{5,7},{8,9},{1,0}},                         {{3,9},{4,7},{4,3},{1,9}},                           {{7,5},{3,8},{5,6},{2,1}}                           };     printf(

Initializing during the array declaration

Program 2

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int marks[2][3][2]={
        {{34,57},{77,79},{64,68}},
        {{62,53},{25,83},{36,76}},
        };
    printf("marks[0][0][0]=%d\n", marks[0][0][0]);
     printf("marks[0][0][1]=%d\n", marks[0][0][1]);
      printf("marks[0][1][0]=%d\n", marks[0][1][0]);
       printf("marks[0][1][1]=%d\n", marks[0][1][1]);
        printf("marks[0][2][0]=%d\n", marks[0][2][0]);
         printf("marks[0][2][1]=%d\n", marks[0][2][1]);
          printf("marks[1][0][0]=%d\n", marks[1][0][0]);
           printf("marks[1][0][1]=%d\n", marks[1][0][1]);
            printf("marks[1][1][0]=%d\n", marks[1][1][0]);
             printf("marks[1][1][1]=%d\n", marks[1][1][1]);
              printf("marks[1][2][0]=%d\n", marks[1][2][0]);
               printf("marks[1][2][1]=%d\n", marks[1][2][1]);
               getch();

    return 0;
}

Wen the above code is executed,it produces te following result

 

" #include <stdlib.h> int main() { int stu_Marks[2][3][2];//3 D array declaration in C int i,j,k;//counter variable declaration printf(

Initializing and displaying using loops

using for loop

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int stu_Marks[2][3][2];//3 D array declaration in C
    int i,j,k;//counter variable declaration

    printf("Enter the elements of the array\n");

    for(i=0; i<2; i++){
        for(j=0; j<3; j++){
          for(k=0; k<2; k++){
        printf("Enter value of marks[%d][%d][%d]=",i,j,k);
          scanf("%d",&stu_Marks[i][j][k]);
    }
    }
    }
    printf("\nDisplay entered elements\n");
    for(i=0; i<2; i++){
        for(j=0; j<3; j++){
          for(k=0; k<2; k++){
        printf("stu_Marks[%d][%d][%d]=%d\n",i,j,k,stu_Marks[i][j][k]);
          }
        }
    }
getch();
    return 0;
}

Wen the above code is executed,it produces te following result

" #include <stdlib.h> int main() { int stu_Marks[2][3][2];//3 D array declaration in C int i,j,k;//counter variable declaration printf(

Program 2

using while loop

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int stu_Marks[2][3][2];//3 D array declaration in C
    int i,j,k;//counter variable declaration

    printf("Enter the elements of the array\n");
i=0;
    while(i<2){
            j=0;
        while(j<3){
                k=0;
          while( k<2){
        printf("Enter value of marks[%d][%d][%d]=",i,j,k);
          scanf("%d",&stu_Marks[i][j][k]);
        k++;
    }
    j++;
    }
     i++;
    }
    printf("\nDisplay entered elements\n");
    i=0;
    while(i<2){
            j=0;
        while(j<3){
                k=0;
          while(k<2){
        printf("stu_Marks[%d][%d][%d]=%d\n",i,j,k,stu_Marks[i][j][k]);
         k++;
          }
    j++;
        }
        i++;
    }
getch();
    return 0;
}

Wen the above code is executed,it produces te following result

 

" #include <stdlib.h> int main() { int stu_Marks[2][3][2];//3 D array declaration in C int i,j,k;//counter variable declaration printf(

Program 3

using do-while loop

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int stu_Marks[2][3][2];//3 D array declaration in C
    int i,j,k;//counter variable declaration

    printf("Enter the elements of the array\n");
i=0;
    do{
            j=0;
        do{
                k=0;
          do{
        printf("Enter value of marks[%d][%d][%d]=",i,j,k);
          scanf("%d",&stu_Marks[i][j][k]);
        k++;
    }while( k<2);
    j++;
    }while(j<3);
     i++;
    }while(i<2);
    printf("\nDisplay entered elements\n");
    i=0;
    do{
            j=0;
        do{
                k=0;
          do{
        printf("stu_Marks[%d][%d][%d]=%d\n",i,j,k,stu_Marks[i][j][k]);
         k++;
          }while(k<2);
    j++;
        }while(j<3);
        i++;
    }while(i<2);
getch();
    return 0;
}

Wen the above code is executed,it produces te following result

"<yoastmark



One dim Array in  Java       One dim Array in  C++       One dim Array in  C

2 dim Array in  Java         2 dime Array in  C++          2 dim Array in  C

3 dim Array in  Java       3 dim Array in  C++              3 dim Array in  C


Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes