Programming Lab Lesson Plan 2023-v1
Programming Lab Lesson Plan 2023-v1
Day 9
Lab Assignments
1. WAP to find out sum of series up to n Enter the The sum of series is
terms value of n: 873612.0
1+22+33+……….+nn 7
2. WAP to find out sum of series up to n Enter the The sum of series is
terms value of n: 13.477573
7
3. WAP to print the following pattern for Enter Row 1 1 1 1
rows = 4 Number : 4 2 2 2 2
1111 3333
2222 4444
3333
4444
4. WAP to print the following pattern Enter Row 1
1 Number : 5 1 2
12 123
123 1234
1234 12345
12345
5. WAP to print the following pattern 1
1 22
22 333
333 4444
4444 55555
55555
6. WAP to print the following pattern Enter the 1 3 7 15 31
1 3 7 15 31……. value of n:
5
7. WAP to print the following pattern Enter the *
* value of n: **
** 5 ***
*** ****
**** *****
*****
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 *****
******* ***
***** *
***
*
21 WAP to print the Enter the value of 1
following pattern n: 21
1 5 123
21 4321
123 12345
4321
12345
Day 11 : 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 Set 1:
an 1-d array. Enter no of elements : The resultant array:
5
12345 162345
Enter the element to
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 Set 2:
be searched : 44 Number not found
Set 2:
Enter no of elements :
5
11 22 33 44 55
Enter the elements to
be searched : 77
2. WAP to Count the total Total number of
number of duplicate elements Input the number of duplicate elements
in an array. elements to be stored found in the array: 2
in the array :5
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 Set 1: Set 1:
multiplication of the numbers
stored in an array of integers. Enter array size: 5 Product of the array
elements = 180
Enter array elements:
12356
4. WAP to find the second Input the size of array The Second largest
largest element in an 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 array Input the position
desired position from an : 5 where to delete: 3
array. Input 5 elements in
the array in The new list is : 1 2
ascending order: 4 5
element - 0 : 1
element - 1 : 2
element - 2 : 3
element - 3 : 4
element - 4 : 5
DAY-12
TOPIC : 1D Arrays
1. WAP to display the array RUN-1 RUN-1
elements in ascending order. Enter how many The Numbers in
numbers :7 ascending order are
Enter the value of 7 2445678
Numbers:-
7645248 RUN-2
The Numbers in
RUN-2 ascending order are
Enter how many 12 34 34 56 56 56 78
numbers :10 90 122 799
Enter the value of 10
Numbers:-
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 Set 1: Set 1:
odd numbers in an 1-d array. Enter number of Even numbers in the
elements in the array: array are: 12 98
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 size of the
array: 5 Reversed array is: 5 4
Enter Array 321
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 indexes 2 and 4
integer sum, find a Enter array elements:
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 Since, 3 is present
element in an array A of size more than N/2
N is an element that appears times, so it is the
more than N/2 times in majority element.
the array.
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},
the task is to rotate the array d = 2
elements to the left by d
positions.
DAY-13 , 14
TOPIC : 2D Arrays
Q# Experiment Details Input Output
1. WAP for a two Displaying values:
dimensional to store Enter no of City : 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 value 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 Matrix:
2*2 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 RUN-1: RUN-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
RUN-2: 222
Enter value of matrix a 2 2 2
222222222 After Multiplication
Enter value of matrix b resultant matrix is
333333333 666
666
666
RUN-2
Value of matrix a
222
222
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 upper Enter no. of rows : 3
triangular. 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 Enter the order of the sum of diagonal values=15
Trace(sum of the square matrix A :- 3
diagonal element) of a Enter the values of
given mxn matrix matrix A
345
689
134
Day 15
Lab Assignments
Q# Experiment Details Input Output
Set 1:
Enter two Set 1:
WAP to add two numbers number: Sum of 17 and 10 = 27
entered through the 17 10
1. keyboard by using a
suitable user defined Set 2: Set 2:
function. Enter two Sum of 5 and -12 = -7
number:
5 -12
WAP to find the factorial of a Set 1:
Enter a number: 5
Set 1:
Factorial of 5 = 120
2. number n by using a
suitable user defined Set 2: Set 2:
function. Enter a number: 0 Factorial of 0 = 1
A Fibonacci sequence is Set 1:
defined as follows: the first Enter Fibonacci Set 1:
and second terms in the term serial Fibonacci term serial
sequence are 0 and 1. number: 2 number: 2
Subsequent terms are found Fibonacci number: 1
3. by adding the preceding two
terms in the sequence (Fi =
Fi-1 + Fi-2). WAP to find out Set 2: Set 2:
the value of nth term of the Enter Fibonacci Fibonacci term serial
Fibonacci sequence by term serial number: 8
writing a suitable user number: 8 Fibonacci number: 13
defined function.
Set 1:
Write a C program to Enter 7
an integer: Set 1:
7 is prime.
4 determine a number is
prime or not using a Set 2: Set 2:
function named as “PRIME”. Enter an integer: 6 is not prime.
6
Set 1: Set 1:
Enter num1: 10 Before Swapping
Write a C program to Enter num2: 20 num1=10
num2=20
5 perform swapping of two
integers using a function After Swapping
SWAP. num1=20
num2=10
Set 2: Set 2:
Enter num1: 15 Before Swapping
Enter num2: 30 num1=15
num2=30
After Swapping
num1=30
num2=15
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
WAP to design a user Enter
the
the elements of
array: 35726
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 odd 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:
determine the sum of Enter a 3x3 size matrix: Sum of the main
2. 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 Set 2:
SUMDIAGONAL. Set 2: Sum of the elements
Enter a 3x3 size matrix: of the given array: 6
111
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
Set 1:
Write a C program to Enter matrix1: Set 1:
5. perform addition of two 1 2 3 Result matrix
matrices and display the 4 5 6 234
result using 3rd matrix. 7 8 9 678
Enter matrix2: 10 11 12
111
222
333
Set 2:
Enter matrix1: Set 2:
123 Result matrix
-4 5 -6 234
7 -8 9 365
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
105
two numbers:
60 GCD of 105 and 60 = 15
2. GCD/HCF of two
numbers by using a Set 2:
recursive function. Enter two numbers: Set 2:
5 70 GCD of 5 and 70 = 5
WAP by designing a Set 1: Set 1:
recursive function to Enter a number: 589 Sum of the digits (up to
3. 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
Write a recursive Set 1: Set 1:
function to count the Input: 13478635 Sum of digits: 37
4 digits of a positive
integer (do also for sumSet 2: Set 2:
of digits) 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 Enterthe
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: Number of digits of 2105 = 4
Enter a number:
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:
4. array to another Please Enter the
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
decimal number to
binary
Lab Assignments
Q# Experiment Details Input Output
1. WAP to find the length of a Programming Length of the entered
string with/without using String is 11
library function for getting
length of the string
2. Write a program to extract How are You weu
last character of every word
present in a sentence.
3. Write a program to 1: KIIT String KIIT University
concatenate two strings 2: University
without using any library
function.
4. Write a program to Set1: Kalinga Set1: Not Palindrom
check whether an
entered string is Set2 : Set2: Palindrome
palindrome or not. Madam
5. Write a C program to Industrial dust
extract a substring 24
from a given string.
Prompt the user to
enter the starting
position and length of
the substring.
6. Write a C program to You are very very
find the largest word in good boy.
a given sentence.
Assume that words are
separated by spaces.
Day : 29
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
user entered values to Enter a character, an Set-2
these members integer, and a double all Values entered all
respectively one by together: together:
one A character: @
and display these 42 integer: 10586
values immediately. 3.14 double: 3.14
Again assign these
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
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