Arrays
Arrays
QUESTION-1
Write a program to input 15 integer elements in an array and sort them in ascending order
using the bubble sort technique.
QUESTION-2
Write a program to accept name and total marks of N number of students in two single
subscripts array name[] and totalmarks[].
Calculate and print:
(i) The average of the total marks obtained by N number of students.
[average = (sum of total marks of all the students) / N] (ii) Deviation
of each student’s total marks with the average.
[deviation = total marks of a student – average]
QUESTION-3
Write a program to input integer elements into an array of size 20 and perform the following
operations:
Display the largest number from the array.
Display the smallest number from the array.
Display sum of all the elements of the array.
Small=a[0]; High=a[0];
for(i=0;i<20;++i)
{ if(a[i]>High)
High=a[i];
if(a[i]<Small)
Small=a[i];
Sum=Sum+a[i];
}
QUESTION-4
Write a program to input and store roll numbers, names and marks in 3 subjects of n number
of students in five single-dimensional arrays and display the remark based on average marks
as given below:
Average marks = Total Marks ÷ 3
Average Marks Remark
85 - 100 EXCELLENT
75 - 84 DISTINCTION
60 - 74 FIRST CLASS
40 - 59 PASS
Less than 40 POOR
The maximum marks in the subject are 100.
QUESTION-5
Write a program to input twenty names in an array. Arrange these names in descending order
of alphabets, using the bubble sort technique.
QUESTION-6
Write a program to accept the year of graduation from school as an integer value from the user.
Using the linear 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}
for(i=0;i<year.length;++i)
{
if(year[i]==n)
{ f=1;
break;
}}
if(f==
1)
System.out.println(“Record exists at the
position”+(i+1)); else
System.out.println(“Record does not exist”);
QUESTION-7
Write a program to input 10 integer elements in an array and sort them in descending
order using bubble sort technique.
QUESTION-8
Write a program to accept the names of 10 cities in a single dimension 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”.
QUESTION-9
Write a program to input and sort the weight of ten people. Sort and display them in descending
order using the selection sort technique.
QUESTION-10
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.
L=0;
N=
F=0;
U=a.length – 1; while(L<=U)
{
M=(L+U)/2;
if(a[M]==N)
{
F=1;
break; }
else if(a[M]<N) L=M+1;
else
U=M-1;
} if(F==1)
System.out.println(“Search success and the
element”+N+”at the position”+(i+1)); else
System.out.println(“Search element not found”);
QUESTION-11
Shasha Travels Pvt. Ltd. gives the following discount to its customers:
Ticket Amount Discount
Above Rs. 70000 18%
Rs. 55001 to Rs. 70000 16%
Rs. 35001 to Rs. 55000 12%
Rs. 25001 to Rs. 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:
SNo. Name Ticket charges Discount Net amount
____ ______ _______________ _________ ____________
Assume that there are 15 customers, first customer is given the serial number 1, next customer
2… and so on.
QUESTION-12
Write a program to store six elements in an array P, and four elements in an array Q and
produce a third array R, containing all elements of arrays P and Q. Display the resultant
array.
Example:
P[] = {4, 6, 1, 2, 3, 10}
Q[] = {19, 23, 7, 8}
R[] = {4, 6, 1, 2, 3, 10, 19, 23, 7, 8}
QUESTION-13
QUESTION-14
Define a class and store the given city names in a single dimensional array. Sort these
names in alphabetical order using the bubble sort technique only.
INPUT: Delhi, Bangalore, Agra, Mumbai, Calcutta OUTPUT: Agra, Bangalore,
Calcutta, Delhi, Mumbai
QUESTION-15
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, 1, 3 Output:
Minimum value: 1
Maximum value: 5
Sum of the elements: 15