Tuesday 19 February 2013

Class X - Arrays

Points to remember:(Refer the class x array post)
1. An array is a collection of values of same data type that are refered by one name.
2. Array subscript begins from 0.
3. Method to receive an array
   example :     int get(int a[])
Section A
1. What will be the output:
public static void main( )
{
    int a[]={5,10,15,20,25};
   int i,j,k=1;
   int m;
   i=++a[1];
   j=a[2]++;
   m=a[i++];
  System.out.println(i);
  System.out.println(j);
  System.out.println(m);
}
2.
public static void main( )
{
int b[]={2,4,6,8};
int i,s;
for(i=o;i<=1;i++)
{
s=b[i]+b[3-i];
System.out.println(s);
}
3. Differentiate linear search and binary search.
Section B
1. Write a program to assign the following values in an array and arrange them in ascending order using bubble sort.
5, 3, 8 ,12, 1, 2,23,16,30

2. Write a program to input a single subscripted variable a[] of 40 integers. Arrange them in descending order using selection sort method.

3. Write a function int search( ) which takes an integer array x[] of 10 integers( which is already arranged in ascending order), and an integer val as a parameters.Search val from the array using binary search and return 1 if val is found else return -1.