import java.util.Scanner;
class rkmin
{
public static void main(String x[])
{
int i,p=0,q=0,n,min,max;
Scanner s=new Scanner(System.in);
System.out.println("Enter Size Of Array :");
n=s.nextInt();
int[] a;//declaration of array
a=new int[n]; // Creation of array with given size
for(i=0;i<n;i++)
{
System.out.printf("\n Element a[%d] :",i);
a[i]=s.nextInt();
}
System.out.print("\n Array elements :");
for(i=0;i<n;i++)
{
System.out.print(a[i]+" ");
}
for(i=0;i<n;i++)
{
System.out.printf("\n ADDRESS=%h ---- ARRAY=a[%d] DATA=%d\n",i*4,i,a[i]);
}
min=a[0];
max=a[0];
for(i=0;i<n;i++)
{
if(a[i]>max)
{max=a[i]; p=i;}
if(a[i]<min)
{min=a[i];q=i;}
}
System.out.println("\n maximum number is :" +max+ " and " + "minimum number is :"+min);
// System.out.println("minimum number is :"+min);
for(i=0;i<n;i++)
{
if(a[i]==max)
System.out.printf("\n ADDRESS=%h ---- ARRAY=a[%d] DATA=%d\n",i*4,i,a[i]);
if(a[i]==min)
System.out.printf("\n ADDRESS=%h ---- ARRAY=a[%d] DATA=%d\n",i*4,i,a[i]);
}
}
}
output:
class rkmin
{
public static void main(String x[])
{
int i,p=0,q=0,n,min,max;
Scanner s=new Scanner(System.in);
System.out.println("Enter Size Of Array :");
n=s.nextInt();
int[] a;//declaration of array
a=new int[n]; // Creation of array with given size
for(i=0;i<n;i++)
{
System.out.printf("\n Element a[%d] :",i);
a[i]=s.nextInt();
}
System.out.print("\n Array elements :");
for(i=0;i<n;i++)
{
System.out.print(a[i]+" ");
}
for(i=0;i<n;i++)
{
System.out.printf("\n ADDRESS=%h ---- ARRAY=a[%d] DATA=%d\n",i*4,i,a[i]);
}
min=a[0];
max=a[0];
for(i=0;i<n;i++)
{
if(a[i]>max)
{max=a[i]; p=i;}
if(a[i]<min)
{min=a[i];q=i;}
}
System.out.println("\n maximum number is :" +max+ " and " + "minimum number is :"+min);
// System.out.println("minimum number is :"+min);
for(i=0;i<n;i++)
{
if(a[i]==max)
System.out.printf("\n ADDRESS=%h ---- ARRAY=a[%d] DATA=%d\n",i*4,i,a[i]);
if(a[i]==min)
System.out.printf("\n ADDRESS=%h ---- ARRAY=a[%d] DATA=%d\n",i*4,i,a[i]);
}
}
}
output:
No comments:
Post a Comment