Pages

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

Monday, 16 December 2019

Program on address calculation in Single Dimensional array

Program on address calculation in Single Dimensional array

import java.util.*;
class sda
{
 public static void main(String args[])
 {
  int item,n;
  Scanner s = new Scanner (System.in);
  System.out.print( " Enter the size of the array ");
  n=s.nextInt();
  //int[] a; // declaration
  //a=new int[n];// creation
  int[] a= new int[n]; // declaration and creation
  for(int i=0;i<n;i++)
   {
    a[i]=s.nextInt();
   }
  System.out.print("\n Array elements : ");
  for(int i=0;i<n;i++)
   {
   System.out.print( a[i] + " ");
   }
  for(int i=0;i<n;i++)
   {
   System.out.printf("\n Address = %h ---- Array = a[%d] ---- Data = %d",i*4,i,a[i]);
   }
  System.out.print("\n Enter the Array element which u want : ");
  item=s.nextInt();
  for(int i=0;i<n;i++)
   {
    if(item == a[i])
   System.out.printf("\n Address = %h ---- Array = a[%d] ---- Data =   %d",i*4,i,a[i]);
   }
  
  }
 }

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...