0% found this document useful (0 votes)
7 views32 pages

PPS Practical Session Program

The document is a practical lab manual for the Programming for Problem Solving course at SRM Institute of Science and Technology for the academic year 2023-2024. It outlines a series of experiments focusing on programming concepts such as input/output statements, data types, control statements, arrays, functions, and Python data structures, along with their respective aims, algorithms, and expected results. Each experiment includes a structured approach to coding, including pseudocode and program code templates.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views32 pages

PPS Practical Session Program

The document is a practical lab manual for the Programming for Problem Solving course at SRM Institute of Science and Technology for the academic year 2023-2024. It outlines a series of experiments focusing on programming concepts such as input/output statements, data types, control statements, arrays, functions, and Python data structures, along with their respective aims, algorithms, and expected results. Each experiment includes a structured approach to coding, including pseudocode and program code templates.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY, RAMAPURAM

FACULTY OF ENGINEERING AND TECHNOLOGY


DEPARTMENT OF MECHANICAL ENGINEERING
ACADEMIC YEAR 2023-2024
PPS Practical Lab Manual

COURSE CODE / TITLE: 21CSS101J – PROGRAMMING FOR PROBLEM SOLVING


No. of hours per week: 02
Total No. of hours: 30

List of Experiments:
Reference
Reference to
Ex. Week Title of Experiment to
Pos & PSOs
No. COs

1 I Input, Output Statements, Variables 1 1,2,3,4,5,8,9,10,12

2 II Data types & Operators-I 1 1,2,3,4,5,8,9,10,12

3 III Data types & Operators-II 1 1,2,3,4,5,8,9,10,12

4 IV Control Statements (Branching, Looping) 2 1,2,3,4,5,8,9,10,12

V Arrays 2 1,2,3,4,5,8,9,10,12
5
6 VI Arrays with Pointers 2 1,2,3,4,5,8,9,10,12

7 VII Strings 3 1,2,3,4,5,8,9,10,12

8 VIII Functions 4 1,2,3,4,5,8,9,10,12

9 IX Arrays and Functions 4 1,2,3,4,5,8,9,10,12

10 X Input, Output in Python 5 1,2,3,4,5,8,9,10,12

11 XI Python data structures 5 1,2,3,4,5,8,9,10,12

12 XII Arrays in Python 5 1,2,3,4,5,8,9,10,12

13 XIII Operations with Numpy 6 1,2,3,4,5,8,9,10,12

14 XIV Operations with Pandas 6 1,2,3,4,5,8,9,10,12

15 XV Case study: Data science with Numpy, Panda 6 1,2,3,4,5,8,9,10,12

Note:

In the observation note, Right side – Aim, Algorithm, Program code and Result
Left Side – Pseudocode, Input, Output
Ex. No: 1a Input, Output Statements, Variables

Aim: To Print Hello, World

Algorithm for the Program:


1. Start the program.
2. Include the standard input-output header file (stdio.h).
3. Define the main() function.
4. Inside the main() function:
• Use the printf() function to print "Hello, World!" to the console.
5. Return 0 to indicate successful execution of the program.
6. End the program.

Pseudocode:

Program Code:

Input:

Output:

Result: The program is executed successfully and the output is verified.


Ex. No: 1b Input, Output Statements, Variables

Aim: To Input and Print a Number

Algorithm for the Program:


1. Start the program.
2. Include the standard input-output header file (stdio.h).
3. Define the main() function.
4. Inside the main() function:
a. Declare an integer variable num.
b. Prompt the user to enter a number using printf().
c. Read the input from the user and store it in num using scanf().
d. Display the entered number using printf().
5. Return 0 to indicate successful execution of the program.
6. End the program.

Pseudocode:
Program Code:

Input:

Output:

Result: The program is executed successfully and the output is verified.


Ex. No: 2a Data types & Operators-I

Aim:
To perform basic arithmetic operations (addition, subtraction, multiplication, and division) on
two predefined integers and display the results.

Algorithm for the Program:


1. Start the program.
2. Include the standard input-output header file (stdio.h).
3. Define the main() function.
4. Inside the main() function:
a. Declare two integer variables, a and b, and assign them values 10 and 5, respectively.
b. Calculate the sum of a and b and print the result using printf().
c. Calculate the difference between a and b and print the result using printf().
d. Calculate the product of a and b and print the result using printf().
e. Calculate the quotient of a divided by b and print the result using printf().
5. Return 0 to indicate successful execution of the program.
6. End the program.

Pseudocode:
Program Code:

Input:

Output:

Result: The program is executed successfully and the output is verified.


Ex. No: 2b Data types & Operators-I

Aim:
To demonstrate the use of relational operators by comparing two integers and displaying the
results of the comparisons

Algorithm for the Program:


1. Start the program.
2. Include the standard input-output header file (stdio.h).
3. Define the main() function.
4. Inside the main() function:
a. Declare two integer variables, x and y, and assign them values 10 and 20,
respectively.
b. Use the relational operator > to check if x is greater than y and print the result (1 for
true, 0 for false).
c. Use the relational operator < to check if x is less than y and print the result (1 for true,
0 for false).
5. Return 0 to indicate successful execution of the program.
6. End the program.

Pseudocode:
Program Code:

Input:

Output:

Result: The program is executed successfully and the output is verified.


Ex. No: 3a Data types & Operators-II

Aim:
To demonstrate the use of logical operators (&& and ||) by evaluating logical expressions and
displaying the results.

Algorithm for the Program:


1. Start the program.
2. Include the standard input-output header file (stdio.h).
3. Define the main() function.
4. Inside the main() function:
o Declare two integer variables, a and b, and assign them values 5 and 10, respectively.
o Use the logical AND operator (&&) to evaluate if a < b and b > 0 are both true. Print
the result (1 for true, 0 for false).
o Use the logical OR operator (||) to evaluate if a > b or b < 0 is true. Print the result (1
for true, 0 for false).
5. Return 0 to indicate successful execution of the program.
6. End the program.

Pseudocode:
Program Code:

Input:

Output:

Result: The program is executed successfully and the output is verified.


Ex. No: 3b Data types & Operators-II

Aim:
To demonstrate the use of bitwise operators (& and |) by performing bit-level operations on
two integers and displaying the results.

Algorithm for the Program:


1. Start the program.
2. Include the standard input-output header file (stdio.h).
3. Define the main() function.
4. Inside the main() function:
a. Declare two integer variables, x and y, and assign them values 5 and 3, respectively.
b. Perform a bitwise AND operation (x & y) and print the result.
c. Perform a bitwise OR operation (x | y) and print the result.
5. Return 0 to indicate successful execution of the program.
6. End the program.
Pseudocode:
Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 4a Control Statements (Branching, Looping)

Aim:
To determine whether a given number is even or odd using the if-else control statement.

Algorithm for the Program:


1. Start the program.
2. Include the standard input-output header file (stdio.h).
3. Define the main() function.
4. Inside the main() function:
a. Declare an integer variable num.
b. Prompt the user to input a number using printf().
c. Read the input value and store it in the variable num using scanf().
d. Use an if statement to check if num % 2 == 0:
i. If true, print that the number is even.
e. Use the else statement to handle the case where the number is odd and print the
appropriate message.
5. Return 0 to indicate successful execution of the program.
6. End the program.

Pseudocode:
Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 4b Control Statements (Branching, Looping)

Aim:
To print numbers from 1 to 5 using a for loop in C.

Algorithm for the Program:


1. Start the program.
2. Include the standard input-output header file (stdio.h).
3. Define the main() function.
4. Inside the main() function:
a. Use a for loop with:
i. Initialization: Set i = 1.
ii. Condition: Continue looping while i <= 5.
iii. Increment: Increase the value of i by 1 after each iteration.
b. Inside the loop, use printf() to display the current value of i.
5. Return 0 to indicate successful execution of the program.
6. End the program.

Pseudocode:
Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 5a Arrays

Aim:
To input 5 integers into an array and then print those integers.

Algorithm for the Program:


1. Declare an array arr[5] to hold 5 integers.
2. Print a message prompting the user to enter 5 numbers.
3. Use a loop to take 5 inputs from the user and store them in the array.
4. Print a message indicating the entered numbers.
5. Use another loop to print all the values stored in the array.
6. End the program.

Pseudocode:
Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 5b Arrays

Aim:
To input 5 integers into an array and calculate the sum of these integers.

Algorithm for the Program:


1. Declare an integer array arr[5] to hold 5 numbers and an integer variable sum initialized to 0.
2. Print a message prompting the user to enter 5 numbers.
3. Use a loop to take 5 inputs from the user, adding each number to the sum variable as they are
entered.
4. After the loop, print the value of sum.
5. End the program.

Pseudocode:
Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 6a Arrays with Pointers

Aim:
To demonstrate how to access array elements using pointers in C by iterating through the array
with pointer arithmetic.

Algorithm for the Program:


1. Start the program.
2. Include the standard input-output header file (stdio.h).
3. Define the main() function.
4. Inside the main() function:
a. Declare an integer array arr and initialize it with values {1, 2, 3, 4, 5}.
b. Declare a pointer ptr and assign it to the base address of the array arr.
c. Use a for loop to iterate from i = 0 to i < 5:
i. Access and print each element of the array using pointer arithmetic (*(ptr +
i)).
5. Return 0 to indicate successful execution of the program.
6. End the program.
Pseudocode:
Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 6b Arrays with Pointers

Aim:
To find the largest element in an array using pointers in C.

Algorithm for the Program:


1. Start the program.
2. Include the standard input-output header file (stdio.h).
3. Define the main() function.
4. Inside the main() function:
a. Declare an integer array arr and initialize it with values {10, 20, 5, 30, 15}.
b. Declare a pointer ptr and assign it to the base address of the array arr.
c. Initialize a variable max with the value of the first element of the array (*ptr).
d. Use a for loop to iterate from i = 1 to i < 5:
i. If the current element (*(ptr + i)) is greater than max, update max with this
value.
5. Print the value of max as the largest element.
6. Return 0 to indicate successful execution of the program.
7. End the program.

Pseudocode:
Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 7a Strings

Aim:
To reverse a given string entered by the user and display the reversed string.
Algorithm for the Program:
[Link] the program.
[Link] the necessary header files (stdio.h and string.h).
[Link] the main() function.
[Link] the main() function:
a. Declare two character arrays str and rev to store the input string and the reversed
string, respectively.
b. Declare two integer variables, len to store the length of the string and i for iteration.
c. Prompt the user to enter a string using printf().
d. Read the input string using scanf() and store it in str.
e. Calculate the length of the string using the strlen() function.
f. Use a for loop to reverse the string:
i. Start from the end of str and copy each character to rev in reverse order.
g. Add a null terminator ('\0') to the end of the reversed string to make it a valid string.
h. Print the reversed string using printf().
5. Return 0 to indicate successful execution of the program.
6. End the program.
Pseudocode:
Program Code:

Input
Output

Result: The program is executed successfully and the output is verified.


Ex. No: 7b Strings

Aim:
To check whether a given string is a palindrome by comparing its characters from the start and the
end.

Algorithm for the Program:


1. Start the program.
2. Include the necessary header files (stdio.h and string.h).
3. Define the main() function.
4. Inside the main() function:
a. Declare a character array str to store the input string.
b. Declare integer variables len for the string length, i for iteration, and isPalindrome
initialized to 1 (true).
c. Prompt the user to enter a string using printf().
d. Read the input string using scanf() and store it in str.
e. Calculate the length of the string using the strlen() function.
f. Use a for loop to iterate through the string up to its midpoint:
i. Compare the character at the current position (str[i]) with the corresponding
character from the end (str[len - i - 1]).
ii. If they are not equal, set isPalindrome to 0 (false) and break out of the loop.
g. Check the value of isPalindrome:
i. If 1, print that the string is a palindrome.
ii. If 0, print that the string is not a palindrome.
5. Return 0 to indicate successful execution of the program.
6. End the program.
Pseudocode:
Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 8a Functions

Aim:
To calculate the factorial of a given number using a recursive function in C.
Algorithm for the Program:
1. Start the program.
2. Include the standard input-output header file (stdio.h).
3. Define a recursive function factorial(int n):
o If n is 0 or 1, return 1 (base case).
o Otherwise, return n * factorial(n - 1) (recursive step).
4. In the main() function:
o Declare an integer variable num.
o Prompt the user to enter a number and read the input using scanf().
o Call the factorial() function with the user-entered number and store the result.
o Print the factorial of the number using printf().
5. Return 0 to indicate successful execution of the program.
6. End the program.
Pseudocode:
Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 8b Functions

Aim:
To find the maximum of two numbers using a function in C.
Algorithm for the Program:
1. Start the program.
2. Include the standard input-output header file (stdio.h).
3. Define the function max(int a, int b):
o Compare the two integers a and b using the conditional (ternary) operator.
o Return a if a > b, otherwise return b.
4. In the main() function:
o Declare two integer variables x and y.
o Prompt the user to enter two numbers and read the input using scanf().
o Call the max() function with x and y as arguments and store the result.
o Print the maximum of the two numbers using printf().
5. Return 0 to indicate successful execution of the program.
6. End the program.
Pseudocode:
Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 9a Arrays and Functions

Aim:
To find the sum of all elements in an array using a function in C.
Algorithm for the Program:
1. Start the program.
2. Include the standard input-output header file (stdio.h).
3. Define the function sumOfArray(int arr[], int size):
o Initialize an integer variable sum to 0.
o Use a for loop to iterate through the array elements:
1. Add each element of the array to sum.
o Return the value of sum.
4. In the main() function:
o Declare and initialize an array arr with values {1, 2, 3, 4, 5}.
o Call the sumOfArray() function with arr and its size as arguments.
o Print the returned sum of the array elements.
5. Return 0 to indicate successful execution of the program.
6. End the program.

Pseudocode:
Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 9b Arrays and Functions

Aim:
To find the largest element in an array using a function in C.

Algorithm for the Program:


1. Start the program.
2. Include the standard input-output header file (stdio.h).
3. Define the function findMax(int arr[], int size):
o Initialize an integer variable max with the value of the first element of the array
(arr[0]).
o Use a for loop to iterate through the array starting from the second element (index 1)
to the last element.
o Compare the current element arr[i] with max:
i. If arr[i] is greater than max, update max with arr[i].
o After the loop ends, return the value of max.
4. In the main() function:
o Declare and initialize an array arr with values {10, 20, 5, 30, 15}.
o Call the findMax() function with arr and its size as arguments.
o Print the largest element returned by the function.
5. Return 0 to indicate successful execution of the program.
6. End the program.

Pseudocode:
Program Code:

Input
Output
Result: The program is executed successfully and the output is verified.
Ex. No: 10a Input, Output in Python

Aim:
To input a string from the user and print a greeting message using the entered string in Python.

Algorithm for the Program:


1. Start the program.
2. Use the input() function to prompt the user to enter their name and store the input in a
variable called name.
3. Use the print() function with an f-string to display a greeting message that includes the user's
name.
4. End the program.

Pseudocode:

Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 10b Input, Output in Python

Aim:
The aim of this program is to take two integer inputs from the user and print those numbers on the
screen.

Algorithm for the Program:


1. Start the program.
2. Prompt the user to input the first number and store it in a variable num1.
3. Prompt the user to input the second number and store it in a variable num2.
4. Print the message displaying the values of num1 and num2.
5. End the program.

Pseudocode:

Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 11a Python Data Structures

Aim:
The aim of this program is to create a list of fruits, display it, add a new fruit to the list, and then display
the updated list.

Algorithm for the Program:


1. Start the program.
2. Initialize a list fruits with some predefined fruit names.
3. Print the list of fruits.
4. Append a new fruit "orange" to the list.
5. Print the updated list of fruits.
6. End the program.

Pseudocode:

Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 11b Python Data Structures

Aim:
The aim of this program is to create a dictionary containing student information, display the entire
dictionary, and retrieve and print the student's name using the dictionary key.

Algorithm for the Program:


1. Start the program.
2. Initialize a dictionary student with keys name, age, and grade, and their respective values.
3. Print the entire student dictionary.
4. Access and print the value associated with the key "name" from the dictionary.
5. End the program.

Pseudocode:

BEGIN
CREATE a dictionary named student with keys "name", "age", "grade" and corresponding values
"John", 21, "A"
PRINT the dictionary student
PRINT the value associated with the key "name" in the dictionary student
END

Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 12a Arrays in Python

Aim:
The aim of this program is to create an array of integers, and then print each element of the array.

Algorithm for the Program:


1. Start the program.
2. Import the array module to work with arrays.
3. Initialize an array arr with integer values [1, 2, 3, 4, 5].
4. Use a loop to iterate over each element in the array.
5. Print each element of the array with a space between them.
6. End the program.

Pseudocode:

Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 12b Arrays in Python

Aim:
The aim of this program is to calculate and print the sum of elements in an array.

Algorithm for the Program:


1. Start the program.
2. Import the array module to handle arrays.
3. Initialize an array arr with integer values [10, 20, 30, 40, 50].
4. Use the built-in sum() function to find the sum of the elements in the array.
5. Print the sum of the array elements.
6. End the program.

Pseudocode:

Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 13a Operations with Numpy

Aim:
The aim of this program is to create a NumPy array with integer values and print the array.

Algorithm for the Program:


1. Start the program.
2. Import the numpy library as np.
3. Initialize a NumPy array arr with the values [1, 2, 3, 4, 5].
4. Print the NumPy array.
5. End the program.

Pseudocode:

Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 13b Operations with Numpy

Aim:
The aim of this program is to perform element-wise addition of two NumPy arrays and print the resultant
array.

Algorithm for the Program:


1. Start the program.
2. Import the numpy library as np.
3. Initialize two NumPy arrays arr1 and arr2 with the values [1, 2, 3] and [4, 5, 6], respectively.
4. Perform element-wise addition of the arrays arr1 and arr2 and store the result in a new array
result.
5. Print the result array.
6. End the program.

Pseudocode:

Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 14a Operations with Numpy

Aim:
The aim of this program is to create a DataFrame using the pandas library and display its contents.

Algorithm for the Program:


1. Start the program.
2. Import the pandas library as pd.
3. Create a dictionary data with keys "Name" and "Age", and corresponding values as lists of
names and ages.
4. Convert the dictionary data into a pandas DataFrame and store it in a variable df.
5. Print the DataFrame df.
6. End the program.

Pseudocode:
BEGIN
IMPORT pandas as pd
CREATE a dictionary named data with keys "Name" and "Age", and values ["Alice", "Bob",
"Charlie"] and [25, 30, 35]
CREATE a DataFrame df from the dictionary data
PRINT the DataFrame df
END

Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 14b Operations with Numpy

Aim:
The aim of this program is to create a DataFrame using the pandas library and display its contents.

Algorithm for the Program:


1. Start the program.
2. Import the pandas library as pd.
3. Create a dictionary data with keys "Name" and "Age", and corresponding values as lists of
names and ages.
4. Convert the dictionary data into a pandas DataFrame and store it in a variable df.
5. Print the DataFrame df.
6. End the program.

Pseudocode:
BEGIN
IMPORT pandas as pd
CREATE a dictionary named data with keys "Name" and "Age", and values ["Alice",
"Bob", "Charlie"] and [25, 30, 35]
CREATE a DataFrame df from the dictionary data
FILTER the DataFrame df for rows where the "Age" is greater than 25
PRINT the filtered DataFrame
END

Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 15a Case Study: Data Science with NumPy and Pandas

Aim:
The aim of this program is to calculate and display the mean and standard deviation of a list of numbers
using NumPy.

Algorithm for the Program:


1. Start the program.
2. Import the numpy library as np.
3. Create a list data with numeric values [1, 2, 3, 4, 5].
4. Use NumPy's mean() function to calculate the mean of the data and store the result.
5. Use NumPy's std() function to calculate the standard deviation of the data and store the result.
6. Print the calculated mean and standard deviation.
7. End the program.

Pseudocode:

Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.


Ex. No: 15b Case Study: Data Science with NumPy and Pandas

Aim:
The aim of this program is to perform basic data analysis using pandas, specifically to calculate the total
sales and average sales of products.

Algorithm for the Program:


1. Start the program.
2. Import the pandas library as pd.
3. Create a dictionary data with keys "Product" and "Sales", and corresponding values as lists of
products and sales figures.
4. Convert the dictionary data into a pandas DataFrame and store it in a variable df.
5. Use pandas' sum() function to calculate the total sales from the "Sales" column.
6. Use pandas' mean() function to calculate the average sales from the "Sales" column.
7. Print the total sales and average sales.
8. End the program.
Pseudocode:
BEGIN
IMPORT pandas as pd
CREATE a dictionary named data with keys "Product" and "Sales", and values ["A", "B", "C"] and
[100, 150, 200]
CREATE a DataFrame df from the dictionary data
CALCULATE the total sales by summing the values in the "Sales" column of df
CALCULATE the average sales by finding the mean of the "Sales" column of df
PRINT the total sales and average sales
END

Program Code:

Input

Output

Result: The program is executed successfully and the output is verified.

You might also like