Vous êtes sur la page 1sur 4

Class XII

Assignment: - 1-D Arrays


Write a UDF which takes an integer array, its size and rotation
factor as parameter and rotate an array a per the rotation factor. If the rotation
factor is 1 then shift last two elements in the beginning of the array and if the
rotation factor is 2 then shift first two elements to the end of the array.
Input array 1,2,3,4,5,6
Rotation factor=1
output - 5, 6, 1, 2, 3, 4
Rotation factor=2
output 3, 4, 5, 6, 1, 2
2.
Write a UDF which takes an integer array, its size as parameter
and sort on the basis of Ones place of the array.
Input 45,29,81,13,37
output 81,13,45,37,29
3.
Write a UDF which takes 2 integer arrays and their sizes as
parameter and merge into a third array. The 2 array are arranges in
descending order but the resultant array should be in ascending order
Input array1-89,76,56,23,13 array1- 78,59,34,12
resultant 12,13,23,34,56,59,76,89
4.
Write a UDF which takes 2 integer arrays, their sizes as
parameter and merge into a 3rd array. The 1st array is arranged in ascending
order and 2nd array is arranged in descending order, the 3 rd array should be in
ascending order.
Input array1 - 34,23,12,8 array2 4,5,18,29 resultant 4,5,8,12,18,23,29,34
5.
Write a UDF which takes an integer array, its size as parameter
and swap the adjacent elements of the array.
Input 1,2,3,4,5,6,78
output 2,1,4,3,6,5,8,7
6.
Write a UDF which takes an integer array, its size as parameter
and display the first 3 largest values.
Input 12,34,23,78,90,27,56,98,87
Output 1st -98 2nd - 90 3rd - 87
7.
Write a UDF which takes 2 integer arrays, their sizes as
parameter and merge into a third array. Place 1 st 5 values of 1st array and last
5 values of the 2nd array. Arrays may or may not be sorted.
Input array1 1,2,3,4,5,6,7,8
array 2 11,12,13,14,15,16,17,18,19
Resultant 1,2,3,4,5,15,16,17,18,19
8.
Write a UDF which takes an integer array, its size as parameter
and divide all those elements by 5 which are divisible by 5 and multiply other
array elements by 2
Input 20,12,15,60,32 output-4,24,3,12,64
9.
Write a UDF which takes an integer array, its size as parameter
which will replace all the odd vales by its thrice and all the even values by its
twice.
Input 2,5,6,1,12,3
output - 4,125,36,1,144,27
10.
Consider the linear array A[-10:10], B[1925:1990, C[25]
a.
Find the number of elements in each array
b.
Suppose base address of A=400 and size is 2
bytes, B=600 and size is 4 bytes, C=900 and size is 1 byte find the
address of A[5], A[-3], B[1970], C[2], C[23].
1.

Assignment 2D
Q1., no of rows and no of columns as parameter and return sum of all the elements
of matrix
Q2. Write a UDF which takes an integer matrix, no of rows and no of columns as
parameter and display sum of even and odd elements of the matrix.
Q3. Write a UDF which takes an integer square matrix, no of rows and no of
columns as parameter and return diagonal total.
Q4. Write a UDF which takes an integer square matrix, no of rows and no of
columns as parameter and display diagonal elements.
Q5. Write a UDF which takes an integer matrix, no of rows and no of columns as
parameter and display maximum and minimum element of the matrix.
Q6. Write a UDF which takes an integer matrix, no of rows and no of columns as
parameter and display total of each row.
Q7. Write a UDF which takes an integer matrix, no of rows and no of columns as
parameter and display total of each column.
Q8. Write a UDF which takes an integer matrix, no of rows and no of columns as
parameter and return the total of row no.3
Input
Output
1234
return 14 (5+6+7+8)
5678
1257
3891
Q9. Write a UDF which takes an integer matrix, no of rows and no of columns as
parameter and return total of column no 2
Input
Output
1234
return 18(2+6+2+8)
5678
1257
3891
Q10. Write a UDF which takes an integer matrix, no of rows and no of columns and
element to find as parameter and return no
of times element appears in the
matrix.
Q11. Write a UDF which takes an integer matrix, no of rows and no of columns as
parameter and display transpose of a matrix.
Q12. Write a UDF which takes an integer matrix, no of rows and no of columns as
parameter and print lower triangle of the matrix
Input
Output
1 2 3 4 5
1
5 6 1 7 9
5 6
3 4 2 1 8
3 4 2
1 2 3 4 6
1 2 3 4
5 6 1 7 8
5 6 1 7 8
Q13. Write a UDF which takes an integer matrix, no of rows and no of columns as
parameter and print lower triangle of the matrix
Input
Output
1 2 3 4 5
5
5 6 1 7 9
7 9
3 4 2 1 8
2 1 8
1 2 3 4 6
2 3 4 6
5 6 1 7 8
5 6 1 7 8
Q14. Write a UDF which takes an integer matrix, no of rows and no of columns as
parameter and print upper triangle of the matrix

Input
Output
1 2 3 4 5
1 2 3 4 5
5 6 1 7 9
5 6 1 7
3 4 2 1 8
3 4 2
1 2 3 4 6
1 2
5 6 1 7 8
5
Q15. Write a UDF which takes an integer matrix, no of rows and no of columns as
parameter and print lower triangle of the matrix
Input
Output
1 2 3 4 5
1 2 3 4 5
5 6 1 7 9
6 1 7 9
3 4 2 1 8
2 1 8
1 2 3 4 6
4 6
5 6 1 7 8
8

Assignment- Strings
Q1. Write UDF which takes a string as parameter and return no of characters in the
string(like strlen(s1);).
Q2. Write UDF which takes a string as parameter and display frequency table of
characters in the string i.e. No of uppercase, no of lowercase, no of digits, no of
special characters, no of words, no of lines.
Q3. Write UDF which takes a 2 strings parameter and copy contents of 1 st string to
2nd string (like strcpy(s1,s2);).
Q4. Write UDF which takes a 2 strings parameter and concatenate contents of 1 st
string to 2nd string (like strcat(s1,s2);).
Q5. Write UDF which takes a 2 strings parameter and compare contents of 1 st string
to 2nd string (like strccmp(s1,s2);).
Q5. Write UDF which takes a 1 string parameter and display lower triangle.
Input
COMPUTER

Output
C
CO
COM
COMP
COMPU
COMPUT
COMPUTE
COMPUTER
Q6.Write UDF which takes a 1 string parameter and display lower triangle.
Input
COMPUTER

Output

Input

Output

R
ER
TER
UTER
PU TER
MPUTER
OMPUTER
COMPUTER
Q7. Write UDF which takes a 1 string parameter and display UPPER triangle.

COMPUTER

COMPUTER
COMPUTE
COMPUT
COMPU
COMP
COM
CO
C
Q8. Write UDF which takes a 1 string parameter and display UPPER triangle.
Input
COMPUTER

Output
COMPUTER
OMPUTER
MPUTER
PUTER
UTER
TER
ER
R
Q9. Write UDF which takes a 1 string parameter and display REVERSE of string.
Input
Output
COMPUTER
RETUPMOC
Q10. Write UDF which takes a 1 string parameter and return 1 if it is a palindrome
and 0 if not.

Vous aimerez peut-être aussi