Sei sulla pagina 1di 17

ASSIGNMENT 2

1.Program to input fifteen numbers in an array and sort them


in ascending order.
Source code:
Output:

Variable description:
Variable Data Type Purpose
a[] int To accept the values
into an array
i int Loop counter
j int Loop counter
t int Temporary variable
2.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}.
Source code:
Output:

Variable description:
Variable Data Type Purpose
a[] int To accept the values
into an array
x int To accept the number
to be searched from
user
l int To store the lower limit
of an array
u int To store the upper limit
of an array
flag int Temporary variable
mid int To store the middle
value of an array
3.Program to accept values in two different arrays and merge
then into a third array. Display the merged array.
Source code:
Output:

Variable description:
Variable Data Type Purpose
m int To accept the size of the
first array from user
n int To accept the size of
second array from user
z int To store the size of first
array
a[] int To accept values into
first array from user
b[] int To accept values into
second array from user
c[] int To store merged array
i int Loop counter
k int Loop counter
4.Program to accept 10 numbers in an array and print the
largest and smallest number present in the array.
Source code:
Output:

Variable description:
Variable Data Type Purpose
a[] int To accept values into an
array from user
i int Loop counter
max int To store maximum
number
min int To store minimum
number
5.Program to display a string in piglatin form.
Source code:
Output:

Variable description:
Variable Data Type Purpose
l int To calculate the length
of the string
i int Loop counter
s String To accept string from
user
w String To store the substring
value
p String To store the substring
value
d String To store the string in
piglatin form
c char To store a character
value
6.Program to assign a full path and file name as given below.
Using library functions, extract and output the file path, file
name and file extension separately as shown.
Input:-C:/Users/admin/Pictures/flower.jpg
Output Path: C:/Users/admin/Pictures/
File name: flower
Extension: jpg
Source code:
Output:

Variable description:
Variable Data Type Purpose
s String To accept and store a
string given by user
p String To store path
q String To store file name
r String To store extension
7.Program to accept a string and print it in reverse order.
Source code:
Output:

Variable description:
Variable Data Type Purpose
i int Loop counter
l int To calculate the length
of string
c char To store the character
value
a String To accept and store a
string given by user
w String To store the string in
reverse order

Potrebbero piacerti anche