0% found this document useful (0 votes)
9 views

Array Worksheet (1)

The document contains a worksheet for Std. X students at C.N.M. School focusing on Computer Applications, specifically on arrays and searching algorithms. It includes programming tasks such as calculating sums, averages, and discounts, as well as implementing linear and binary search techniques. The tasks are designed to enhance students' understanding of arrays and their applications in programming.

Uploaded by

Hiral Bhatt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Array Worksheet (1)

The document contains a worksheet for Std. X students at C.N.M. School focusing on Computer Applications, specifically on arrays and searching algorithms. It includes programming tasks such as calculating sums, averages, and discounts, as well as implementing linear and binary search techniques. The tasks are designed to enhance students' understanding of arrays and their applications in programming.

Uploaded by

Hiral Bhatt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Shri Vile Parle Kelavani Mandal's

C.N.M.School & N.D.Parekh Pre-Primary School


Academic year 2023-2024
Std. X Subject: Computer Application
Worksheet – Array
1. Accept a list of 10 integers from the users and print their sum and average using arrays.
2. WAP which accepts 10 names in an array and displays them in uppercase.
3. Write a class to input name and corresponding age of twenty people in two separate single dimensional
arrays. Print name and corresponding age of only senior citizens.
4. Initialize an array year[] with the values inputted from the keyboard. WAP that prints the number of leap
years inputted.
5. WAP to accept 10 numbers from user and print number with its square and cube value.
Number Square Cube
2 4 8
6. WAP to accept two arrays of 20 nos. and 10 nos. respectively and store the sum of corresponding element in
a new array and display it.
7. WAP that accepts 20 numbers from the user and prints only the even numbers together after storing in
another array.
8. WAP to store list of roll numbers and total marks of 35 students of a class. Print the maximum total marks
and the roll number of the student who obtained it.
9. Write a program to initialize the given data in an array and find the minimum and maximum values along
with the sum of the given elements.
Numbers: 2 5 4 l 3
Output: Minimum value : l
Maximum value : 5
Sum of the elements : 15
10. Write a program to store 6 elements in an array P, and 4 elements in an array Q and produce a third array R,
containing all elements of array P and Q. Display the resultant array
P[ ] = 4,6,8,7,5,9 Q[ ] = 8,2,1,3
R[ ] = 4,6,8,7,5,9, 8,2,1,3
11. Shasha Travels Pvt. Ltd. gives the following discount to its customers:
Ticket Amount Discount
Above Rs. 70000 18%
Rs. 55001 to 70000 16%
Rs. 35001 to 55000 12%
Rs. 25001 to 35000 10%
less than Rs. 25001 2%
Write a program to input the name and ticket amount for the customer and calculate the discount amount and
net amount to be paid. Display the output in the following format for each customer :
Sr. No. Name Ticket charges Discount Net amount
1 – – – –
(Assume that there are 15 customers, first customer is given the serial number (Sr. No.) 1, next customer 2 …
and so on)
12. The marks obtained by 50 students in a subject are tabulated as follows:-
Name Marks
. .
.
. .
Write a program to input the names and the marks of the students in the subject.
Calculate and display:-
(i) The subject average marks (Subject average marks = subject total / 50)
(ii) The highest mark in the subject and the name of the student.
(The maximum marks in the subject are 100)

13. Write a program to input an array of 50 different integers (including negative and positive) and display the
elements in such a way that the negative elements should be printed first followed by the positive elements.
(Consider zero (0) as positive).

****************************************************************************
Worksheet – Array (Searching)
Simple Searching (Linear Search): In this method each element is compared with the value to be searched in a
sequential manner. The search is also termed as sequential search. Since each element is checked the searching
speed becomes also for arrays with large number of elements.
class simple_search
{
public void demo()
{
double[] data={2,14,5,6,7,3,4};
int target=4;
int pos=0;
for(int i=0;i<7;i++)
{
if(data[i]==target)
{
pos=i+1;
}
}
if(pos>0)
System.out.println("The position of the given number is : " +pos);
else
System.out.println("Not found");
}
}
Binary Search : In this method the array element which is passed should be in sorted format. The middle
element of the sorted array is found out, it is checked with the value to be searched.
a) if search value is greater then middle element then left side elements are ignored from search process.
b) if search value is less then middle element then right side elements are ignored from search process.
c) if search value is equal the middle element then position of elements we are searching is determined.
If element is not found step a) or b) or c) are repeated till the element is found.
Linear Search Binary Search
1. The array elements need not be in a sorted The array elements should be in a sorted
format. format.
2. It checks for each element in the array, so In this process most of the elements are
searching process becomes slow when skipped during the searching process so binary
records are many. search is fast.
import java.util.*;
public class array
{
public static void main( )
{
int first, last, mid;
int arr[]=new int[5];
Scanner sc=new Scanner(System.in);
System.out.println("ENTER 5 NUMBERS IN ASCENDING ORDER :");
for(int i=0;i<5;i++)
{
arr[i]=sc.nextInt();
}
last=4;
first=0;
System.out.println("Enter a number to search in the list : ");
int value=sc.nextInt();
mid=(first+last)/2;
while(value!=arr[mid])
{
if(value<arr[mid])
last=mid-1;
if(value>arr[mid])
first=mid+1;
mid=(first+last)/2;
}
System.out.println("Position is of the given no. is : " + (mid+1));
}
}
***************************************
1. Write a program to initialize an array of 5 names and initialize another array with their respective
telephone numbers. Search for a name input by the User, in the list. If found, display "Search
Successful" and print the name along with the telephone number, otherwise display "Search
unsuccessful. Name not enlisted".
2. Write a program to accept the names of 10 cities in a single dimension string array and their STD
(Subscriber Trunk Dialing) codes in another single dimension integer array. Search for a name of a city
input by the user in the list. If found, display “Search Successful” and print the name of the city along
with its STD code, or else display the message “Search Unsuccessful. No such city in the list”.
3. Write a program to accept a number which to be search form the following array using binary search
technique.
4 7 11 18 29 45 71 80 87 93 96 99
4. Write a program to accept the year of graduation from school as an integer value from the user. Using
the Binary Search technique on the sorted array of integers given below, output the message “Record
exists” if the value input is located in the array. If not, output the message “Record does not exist”.
{1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010}
5. Write a program to perform binary search on a list of integers given below, to search for an element
input by the user, if it is found display the element along with its position, otherwise display the message
“Search element not found” 5,7,9,11,15,20,30,45,89,97
import java.util.Scanner;

public class BinarySearch


{
public static void main()
{
int[ ] array = {5, 7, 9, 11, 15, 20, 30, 45, 89, 97};
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number you want to search for: ");
int target = scanner.nextInt();
int left = 0;
int right = array.length - 1;
int result = -1;
while(left <= right)
{
int middle = (left + right) / 2;
if(array[middle] == target)
{
result = middle;
break;
}
else if(array[middle] > target)
{
right = middle - 1;
}
else
{
left = middle + 1;
}
}
if(result != -1)
System.out.println(target + " found at index "+ (result+1));
else
System.out.println("Search element not found");
} }
*****************************************

You might also like