Pages

Showing posts with label Program on address calculation in Multi Dimensional array. Show all posts
Showing posts with label Program on address calculation in Multi Dimensional array. Show all posts

Monday, 16 December 2019

Program on address calculation in Multi Dimensional array

Program on address calculation in Multi Dimensional array
import java.util.*;

class mda
{
 public static void main (String args[])
 {
  int item,m,n,o;
  Scanner s = new Scanner (System.in);
  System.out.print( " Enter the size of the dimensions : ");
  m=s.nextInt();
  System.out.print( " Enter the size of the row : ");
  n=s.nextInt();
  System.out.print( " Enter the size of the column : ");
  o=s.nextInt();
  //int[] a; // declaration
  //a=new int[n];// creation

  int[][][] a= new int[m][n][o]; // declaration and creation
  System.out.printf("\n Enter %d Elements ",m*n*o);
  for(int i=0;i<m;i++)
   {
   for(int j=0;j<n;j++)
    {
   for(int k=0;k<o;k++)
     {
      System.out.printf("\n Elements a[%d][%d][%d] =",i,j,k);
      a[i][j][k]=s.nextInt();
     }
    }
   }
  System.out.print("\n Array elements : ");
  for(int i=0;i<m;i++)
   {
    for(int j=0;j<n;j++)
     {
     for(int k=0;k<o;k++)
      {
       System.out.print( a[i][j][k] + " ");
      }
     }
   }
  for(int i=0;i<m;i++)
   {
    for(int j=0;j<n;j++)
     {
     for(int k=0;k<o;k++)
      {
       System.out.printf("\nArray = a[%d][%d][%d] ---- Data = %d",i,j,k,a[i][j][k]);
      }
     }
   }
  System.out.print("\n Enter the Array element which u want : ");
  item=s.nextInt();
  for(int i=0;i<m;i++)
   {
   for(int j=0;j<n;j++)
    {
    for(int k=0;k<o;k++)
     {
     if(item == a[i][j][k])
      System.out.printf("\nArray = a[%d][%d][%d] ---- Data =   %d",i,j,k,a[i][j][k]);
     }
    }
   }
  }
 }

output:

Constructors & Destructors in c++

  Constructors :  A Constructor is a special member function, which is used to initialize the objects of its class. The Constructor is invok...