PL LAB Autumn
PL LAB Autumn
Home Assignments
Q# Experiment Details Input Output
1 WAP to find out factors of a Set 1 Set 1
number. n=6 The factors are
1236
Set 2 Set 2
n=21 The factors are
1 3 7 21
2 WAP to test whether a number is Set 1 Set 1
Armstrong Number or not. n=153 The given number is
(A number is said to be Armstrong
Armstrong when the sum of Set 2 Set 2
cubes of its digit is equal with the n=121 The given number is not
original number. Armstrong
Ex-153)
3 WAP to test whether a number is Set 1 Set 1
Palindrome Number or not. n=234 The given number is not
(A number is said to be Palindrome
Palindrome when its reverse is Set 2 Set 2
equal with the original number. n=121 The given number is
Ex-121) Palindrome
Day 8
Lab Assignments
Assignments
Home Assignments
1. WAP to print the Enter the value of *
following pattern n: ***
* 5 *****
*** *******
***** *********
*******
*********
2. WAP to print the Enter the value of A
following pattern n: BA
A 5 CBA
BA DCBA
CBA EDCBA
DCBA
EDCBA
3. Write a C program to Enter the value of * * * * *
print a hollow square n: * *
pattern using a while 4 * *
loop. For row=4 *****
*****
* *
* *
*****
4. WAP to print the Enter the value of *********
following pattern n: *******
********* 5 *****
******* ***
***** *
***
*
5 WAP to print the Enter the value of 1
following pattern n: 21
1 5 123
21 4321
123 12345
4321
12345
Home Assignments (Book Exercises)
Q# Experiment Details
1. Page No: 208, Exercise 7.6
2. Page No: 209, Exercise 7.12
DAY 11
TOPIC: 1-D Arrays
Lab Assignments
Q# Experiment Details Input Output
1. WAP to create an array that Enter array size (N): 5 Array Contents are:
can store N integers and Enter number1: 45 45 35 38 31 49
display the contents of the Enter number2: 35
array Enter number3: 38
Enter number4: 31
Enter number5: 49
2. WAP to find out the sum of Enter array size (N): 5 Sum of the numbers
the N numbers stored in an Enter number1: 45 stored in array: 198
array of integers. Enter number2: 35
Enter number3: 38
Enter number4: 31
Enter number5: 49
3. WAP to find the average of N Enter array size (N): 5 Average of the
numbers using arrays. Enter number1: 45 numbers stored in
Enter number2: 35 array = 39.6
Enter number3: 38
Enter number4: 31
Enter number5: 49
4. WAP to find largest element Enter array size (N): 5 Largest element
stored in an array. Enter number1: 45 stored in an array:
Enter number2: 35 45
Enter number3: 38
Enter number4: 31
Enter number5: 49
5. WAP to insert an element in Enter no of elements:
an 1-D array. 5 The resultant array:
12345
Enter the element to 162345
be inserted: 6
Enter the location: 2
PRACTICE ASSIGNMENT
1. WAP to search an element in Set 1: Set 1:
an 1-D array. Enter no of elements: Number found at the
5 location = 4
11 22 33 44 55
Enter the elements to
be searched: 44
Set 2: Set 2:
Enter no of elements: Number not found
5
11 22 33 44 55
Enter the elements to
be searched: 77
2. WAP to Count the total Input the number of Total number of
number of duplicate elements elements to be stored duplicate elements
in an array. in the array: 5 found in the array: 2
Input 5 elements in
the array:
element - 0: 1
element - 1: 1
element - 2: 2
element - 3: 3
element - 4: 3
3. WAP to find out the Enter array size: 5 Product of the array
multiplication of the numbers elements = 180
stored in an array of integers. Enter array elements:
12356
4. WAP to find the second Input the size of The Second largest
largest element in an array. array: 5 element in the array
Input 5 elements in is: 6
the array:
element - 0: 2
element - 1: 9
element - 2: 1
element - 3: 4
element - 4: 6
5. WAP to delete an element at Input the size of The new list is: 1 2
desired position from an array: 5 4 5
array. Input 5 elements in
the array in
ascending order:
element - 0: 1
element - 1: 2
element - 2: 3
element - 3: 4
element - 4: 5
Input the position
where to delete: 3
DAY-12
TOPIC: 1-D Arrays (Contd…)
1. WAP to display the array Set-1 Set-1
elements in ascending order. Enter how many The Numbers in
numbers: 7 ascending order are
Enter the 7 Numbers: 2445678
7645248
Set-2 Set-2
Enter how many The Numbers in
numbers :10 ascending order:
Enter the 10 12 34 34 56 56 56 78
Numbers: 90 122 799
12 34 56 78 90 34 56
799 122 56
2. WAP to Print all unique Input the number of The unique elements
elements of an array. elements to be stored found in the array
in the array: 4 are:
Input 4 elements in 35
the array:
element - 0: 3
element - 1: 2
element - 2: 2
element - 3: 5
3. WAP to print all the even and Enter number of Even numbers in the
odd numbers in an 1-D elements in the array: array are: 12 98
array. 6
Enter 6 elements in Odd numbers in the
the array: 12 19 45 array are: 19 45 69
69 98 23 23
4. WAP to reverse the array Set 1: Set 1:
elements. Enter number of
elements in the array: Elements in reverse
5 order in the array:
Enter these Array 54321
Elements: 1 2 3 4 5
5. Given an array arr[] of Input: Sum found between
non-negative integers and an Enter array size: 6 and including indices
integer sum, find a Enter array elements: 2 and 4
subarray that adds to a given 1 4 20 3 10 5
sum. Enter sum = 33
PRACTICE ASSIGNMENT
1. Given an integer array, find Enter array size: 5 The peak element is
the peak element in it. A Enter array elements: 15
peak element is an element 8 9 10 12 15
that is greater than its
neighbours. There might be
multiple peak elements in an
array, and the solution
should report any peak
element.
2. Given an array A of N Enter array size: 5 3
elements. Find the majority Enter array elements:
element in the array. A 3 1 3 3 2 (Explanation:
majority element in an array Since, 3 is present
A of size N is an element that more than N/2
appears more than N/2 times times, so it is the
in the array. majority element.)
3. Given an array of integers arr[] = Output: 3 4 5 6 7 1 2
arr[] of size N and an integer {1, 2, 3, 4, 5, 6, 7},
d, the task is to rotate the d = 2
array elements to the left by
d positions.
DAY-13, DAY-14
TOPIC: 2D Arrays
Q# Experiment Details Input Output
1. WAP for a two Displaying values:
dimensional to store Enter no of Cities: 2
and display the City 1, Day 1 = 33
elements. (Store 1 2 City 1, Day 2 = 34
temperature of two City 1, Day 3 = 35
cities for a week and Enter no of days: 7 City 1, Day 4 = 33
display it) City 1, Day 5 = 32
Enter the Temp: City 1, Day 6 = 31
(Chosen values) City 1, Day 7 = 30
City 2, Day 1 = 23
City 2, Day 2 = 22
City 2, Day 3 = 21
City 2, Day 4 = 24
City 2, Day 5 = 22
City 2, Day 6 = 25
City 2, Day 7 = 26
2. WAP to find the sum of Enter elements of 1st
two matrices of order matrix Sum of Matrices:
2x2 using Enter a11: 2; 2.2 0.5
multidimensional Enter a12: 0.5;
arrays. Enter a21: -1.1; -0.9 25.0
Enter a22: 2;
Enter elements of 2nd
matrix
Enter b11: 0.2;
Enter b12: 0;
Enter b21: 0.23;
Enter b22: 23;
3. WAP to multiply two Set-1: Set-1
matrices and display it. Enter value of matrix A Value of matrix a
111111111 111
Enter value of matrix B 111
222222222 111
Value of matrix b
222
222
222
After Multiplication
resultant matrix is
666
666
666
Set-2: Set-2
Enter value of matrix a Value of matrix a
222222222 222
Enter value of matrix b 222
333333333 222
Value of matrix b
333
333
333
After Multiplication
resultant matrix is
18 18 18
18 18 18
18 18 18
4. WAP to find the sum of Set 1: Set 1:
elements of a matrix in Enter no. of rows: 3
its upper triangle. Enter no. of cols: 3 The given matrix is:
Enter values to the 9 8 7
matrix : 6 5 4
Enter a [0][0] value: 9 3 2 1
Enter a [0][1] value: 8
Enter a [0][2] value: 7 Sum of upper triangular
Enter a [1][0] value: 6 matrix = 19
Enter a [1][1] value: 5
Enter a [1][2] value: 4
Enter a [2][0] value: 3
Enter a [2][1] value: 2
Enter a [2][2] value: 1
4. WAP to find the Trace Enter the order of the sum of diagonal values=15
(sum of the diagonal square matrix A: 3
elements) of a given m Enter the values of
xn matrix matrix A
345
689
134
Home Assignments (Book Exercises)
Q# Experiment Details
1. Page No: 254, Exercise 8.3
2. Page No: 255, Exercise 8.5
Day: 16
TOPIC: Functions with 1D Arrays
Lab Assignments
Q# Experiment Details Input Output
Set 1: Set 1:
Enter the size of the Sum of the elements of the
array: 5 given array: 23
Enter the elements
WAP to design a user the array: 3 5 7 2 6 of
defined function to
1. calculate the sum of the Set 2:
elements of an integer Enter the size of the SetSum
2:
of the elements of the
1-D array. array: 3 given array: 3
Enter the elements of
the array: 5 0 -2
Set 1: Set 1:
Enter the size of the Before sorting elements of
array: 5 the given array: 3 5 7 2 6
WAP to sort the elements Enter the elements of After sorting elements of
of an 1-D array in the array: 3 5 7 2 6 the given array: 2 3 5 6 7
2. ascending order by using Set 2:
a suitable user defined Set 2: Before sorting elements of
function for sort Enter the size of the the given array: 5 0 -2
operation. array: 3 After sorting elements of
Enter the elements of the given array: -2 0 5
the array: 5 0 -2
Set 1: Set 1:
Enter the size of the Largest element of array is
Write a C program to array: 5 7
determine the largest Enter the elements of Smallest element of array is
and smallest element of the array: 3 5 7 2 6 2
3. a 1-D array. Use
functions LARGEST and Set 2: Set 2:
SMALLEST for the given Enter the size of the Largest element of array is
purpose. array: 3 5
Enter the elements of Smallest element of array is
the array: 5 0 -2 -2
Set 1:
Enter the size of the Set 1:
array: 5
Write a C program to Enter the elements of Second
array is
largest element of
6
determine the second the array: 3 5 7 2 6
4. largest element of a 1-D
array of using a function Set 2:
SECLARGEST. Enter the size of the Set 2:
Second largest element of
array: 3 array is 0
Enter the elements of
the array: 5 0 -2
Set 1:
Enter the size of the Set 1:
array: 5 Entered array: 3 5 7 2 6
Enter the elements of Array after swapping: 6 5 7
Write a C program to the array: 3 5 7 2 6 2 3
5. swap the first and last
element of a 1-D array of Set 2:
using a function SWAP. Enter the size of the Set 2:
array: 3 Entered array: 5 0 -2
Enter the elements of Array after swapping: -2 0
the array: 5 0 -2 5
Set 2:
Enter the size of the
array: 3
Enter the elements of
the array: 5 0 -2
Set 1:
Write a C program to Enter the size of the Set 1:
find the sum of only array: 5 Sum of prime values = 15
PRIME values in a 1-D Enter the elements of Set 2:
3. array using a function the array: 3 5 7 2 6 Sum of prime values = 5
PRIMESUM. Set 2:
Enter the size of the
array: 3
Enter the elements of
the array: 5 0 -2
Day: 17
TOPIC: Functions with 2D Arrays
Lab Assignments
Q# Experiment Details Input Output
Set 1:
Enter the row and
column size of the
matrix: 3 4
Enter the matrix: Set 1:
4 5 6 2 Sum of the elements
1 9 3 0 of the given array: 44
Write a C program to 7 -2 1 8
determine the sum of
1. elements of a 2-D array Set 2:
using a function Enter the row and Set 2:
ELESUM. column size of the Sum of the elements
matrix: 5 3 of the given array: 38
Enter the matrix:
5 6 2
4 3 0
-7 1 8
4 4 5
0 3 0
Write a C program to Set 1: Set 1:
2. determine the sum of Enter a 3x3 size matrix: Sum of the main
main diagonal elements 1 2 3 diagonal elements of
of a 2-D array of size 3x3 4 5 6 the given array: 15
using a function 7 8 9
SUMDIAGONAL. Set 2: Set 2:
Enter a 3x3 size matrix: Sum of the elements
111 of the given array: 6
222
333
Set 1:
Enter the row and
column size of the
matrix: 3 4 Set 1:
Enter the matrix: Largest element of
4 5 6 2 array is 9
Write a C program to 1 9 3 0 Smallest element of
determine the largest 7 -2 1 8 array is -2
and smallest element of
3. a 2-D array. Use Set 2:
functions LARGEST and Enter the row and Set 2:
SMALLEST for the given column size of the Largest element of
purpose. matrix: 5 3 array is 8
Enter the matrix: Smallest element of
5 6 2 array is -7
4 3 0
-7 1 8
4 4 5
0 3 0
Set 1:
Enter the row and
column size of the
matrix: 3 4
Enter the matrix: Set 1:
4 5 6 2 Sum of prime
Write a C program to find 17 -29 31 08 elements = 17
the sum of only PRIME
4. values in a 2-D array Set 2:
using a function Enter the row and
PRIMESUM. column size of the Set 2:
matrix: 5 3 Sum of prime
Enter the matrix: elements = 18
5 6 2
4 3 0
-7 1 8
4 4 5
0 3 0
Write a C program to Set 1:
5. perform addition of two Enter matrix1: Set 1:
matrices and display the 1 2 3 Result matrix
result using 3rd matrix. 4 5 6 234
Use a function 7 8 9 678
ADDMATRIX Enter matrix2: 10 11 12
111
222
333
Set 2:
Enter matrix1: Set 2:
123 Result matrix
-4 5 -6 234
7 -8 9 -3 6 -5
Enter matrix2: 8 -7 10
111
111
111
Day 18
Recursion
Lab Assignments
Q# Experiment Details Input Output
WAP to find the factorial Set 1: Set 1:
of a number n by writing Enter a number: 4 Factorial of 4 = 24
1. a recursive function for
it. Set 2: Set 2:
Enter a number: 1 Factorial of 1 = 1
Set 1: Set 1:
WAP to calculate Enter two numbers: GCD of 105 and 60 = 15
2. GCD/HCF of two 105 60
numbers by using a Set 2:
recursive function. Enter two numbers: Set 2:
5 70 GCD of 5 and 70 = 5
3. WAP by designing a Set 1: Set 1:
recursive function to Enter a number: 589 Sum of the digits (up to
calculate the sum of the single digit) of 589 = 4
digits of any given Set 2: Set 2:
integer until it becomes Enter a number: 25 Sum of the digits (up to
a single digit number. single digit) of 25 = 7
Set 1: Set 1:
Write a recursive Input: 13478635 Sum of digits: 37
4 function to add the digits
of a positive integer. Set 2: Set 2:
Input: 5875014 Sum of digits: 30
Set 1: Set 1:
Enter the size of the Entered Array: 3 5 7 2 6
array: 5 Maximum elements of the
WAP to find out the Enter the
the elements of
array: 35726
given array: 7
5 maximum element of an
integer array by using Set 2:
recursion. Set 2:
Enter the size of the Entered Array: 5 0 -2
array: 3 Maximum elements of the
Enter the elements of given array: 5
the array: 5 0 -2
Home Assignments (Practice Problems)
Q# Experiment Details Input Output
WAP to count number
of digits of a positive Set 1: Set 1:
integer n by using a Enter a number: Number of digits of 10 = 2
1. recursive function. 10
Set 2: Set 2:
Enter a number: Number of digits of 2105 = 4
2105
WAP to find the nth
Fibonacci number Set 1: Set 1:
using recursion. Enter the value of n = 10
n: 10 nth Fibonacci number =
2. 34
Set 2: Set 2:
Enter the value of n=4
n: 4 nth Fibonacci number = 2
Write a recursive Set 1: Set 1:
function to reverse a Input: Hello Output: olleH
3 null terminated string
Set 2: Set 2:
Input: I am going to Output: .loohcs ot gniog ma I
school.
Write a recursive Input: Please Enter Output: Elements of Second
function to copy one the Array Size: 5 Array are:
array to another. Please Enter the
4. Array Elements: 3 Value Inside Array b[0] = 3
5 Value Inside Array b[1] = 5
7 Value Inside Array b[2] = 7
8 Value Inside Array b[3] = 8
9 Value Inside Array b[4] = 9
Set 1: Set 1:
Write a recursive Input: 765 Output: 1011111101
5. function to convert a Set 2: Set 2:
decimal number to Input: 123 Output: 1111011
binary
Home Assignments (Book Exercises)
Q# Experiment Details
1. Page No: 344, Exercise 10.3
2. Page No: 344, Exercise 10.9
Lab Assignments
Day: 25
TOPIC : Structure and Union
Lab Assignments
Q# Experiment Details Input Output
1 WAP to declare an Set-1 Set-1
union named as ABC Values entered one by one: Character: A
having three Enter a character: A Integer: 42
members a, b and c Enter an integer: 42 Double: 3.140000
as character, integer Enter a double: 3.14
and double
respectively. Assign Set-2 Set-2
user entered values to Enter a character, an Values entered all
these members integer, and a double all together:
respectively one by together: character: @
one and display these A integer: 10586
values immediately. 42 double: 3.14
Again, assign these 3.14
user entered values to
a, b, c one by
one, all together and
display these values
at last. Find the
difference.
2 Use structures to Set-1 Set-1
perform addition, Enter the real and You have entered 1st no.
subtraction, imaginary units of first As = 7.0 + 8.0 i
multiplication and complex number: You have entered 2nd no.
division operations on First real = 7 As = 3.0 + 6.0 i
two complex First Imaginary = 8
numbers. Enter the real and What do you want to do?
imaginary units of the Press e for exit
second complex number: Press a for addition
Second real = 3 Press s for subtraction
Second Imaginary = 6 Press m for multiplication
Press d for division: a
Your ans is:
10.0 + 14.0 i
What do you want to do?
Press e for exit
Press a for addition
Press s for subtraction
Press m for multiplication
Press d for division: s
Your ans is:
4.0 + 2.0 i
What do you want to do?
Press e for exit
Press a for addition
Press s for subtraction
Press m for multiplication
Press d for division: m
Your ans is:
-27.0 + 66.0 i
What do you want to do?
Press e for exit
Press a for addition
Press s for subtraction
Press m for multiplication
Press d for division: d
Your ans is:
1.5 + 0.4 i
What do you want to do?
Press e for exit
Press a for addition
Press s for subtraction
Press m for multiplication
Press d for division : e
3 Use an array of Set-1 Set-1
structures to
calculate the gross What do you want to do? Enter employee details:
salary and solve the A. Enter new employee First Name: Arjun
increment issue in an details: Last Name: Mohanty
office. Also, calculate B. Search employee details: Enter Category: Clerk
the new salary C. Increment the salary: A Enter Address: Patia
structure after Square, Kalarahanga
increment. Given What do you want to do? Enter Basic Salary:
basic: Rs 12500, DA: A. Enter new employee 12500
50%, and HRA 10%. details:
B. Search employee details:
C. Increment the salary: B Enter First Name: Arjun
What do you want to do? Name: Arjun Mohanty
A. Enter new employee Address: Patia Square,
details: Kalarahanga
B. Search employee details: Gross Salary: 20000
C. Increment the salary: C
Enter First Name: Arjun
What do you want to do? Percentage Increase: 10
A. Enter new employee
details: Enter First Name: Arjun
B. Search employee details:
C. Increment the salary: B Name: Arjun Mohanty
Address: Patia Square,
Kalarahanga
Gross Salary: 22000
Grading Policies:
Assessment Weightage /
Sl Internal/Sessional Marks
No. Component
Reference Materials:-
1. Text books
T1: Programming in ANSI C (8th Edition) by E. Balagurusamy
2. Reference books
R1: The C Programming Language by Brian Kernighan and Dennis Ritchie
(Second Edition)
3. Links to e-resources (NPTEL, YouTube, Swayam, Virtual lab etc)
● https://onlinecourses.nptel.ac.in/noc22_cs40/preview