0% found this document useful (0 votes)
84 views

Lab and Home Assignment Sheet - 2022

Uploaded by

Koushik Debnath
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)
84 views

Lab and Home Assignment Sheet - 2022

Uploaded by

Koushik Debnath
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
You are on page 1/ 10

Lab and Home Assignment Sheet

Programming for Problem Solving Lab (CSEN-1051)

Name: ......................................................................
Roll: ......................................................................

Department of Computer Science and Engineering


Heritage Institute of Technology, Kolkata, INDIA
B.Tech 1st Yr, Spring – 2019

Copyright © Department of CSE, Heritage Institute


of Technology. All rights reserved.
Getting to know the rules

Before you step foot in the lab


 Make sure that you have the assignment sheet with you.
 Make sure you have the homework copy, with all assignments attempted, ready for
submission.
 Make sure you are not more than 15 minutes late.
 Make sure that you have attended 75% of the CS 201 classes starting from the previous
day of lab.
 If any of these conditions turns out to be FALSE for you, then please stay out of the lab.
Prerequisites

Basic 10th grade Mathematics.

Basic aptitude, interest, and sincerity. NB: If you are sick or feel that you are not
in the right state of the mind to attend the lab, please do not come to the lab but
make sure to inform the class teacher.

Rules of the lab

 Please continue to sit in you allocated seat throughout the semester.


 Please open LINUX environment only. ID and password will be provided on the first
day.
 While leaving make sure that you have signed the attendance sheet and turned off all the
devices you had turned on after entering the lab.
 Try the lab assignments before coming to the lab. Don't come unprepared.
 Please do not copy home assignment from others.
 Violating any of these rules will subject a student to disciplinary action.

Evaluation procedure

 Attendance and everyday performance will add to the internal evaluation.


On the last lab day, a viva-voce will be conducted to evaluate the student's learning of the
subject.

 Final 60 marks lab exam will be conducted on the dates scheduled.

 On the day of the final exam, the signed assignment sheets need to be submitted. In case
of lost assignment sheets, the evaluation cannot be made properly. Every lost
assignment sheet, 4 marks will be deducted from the student's internal marks for
creating an obstacle in the evaluation process.
Day 1: LINUX commands and LINUX based editor

Lab Assignment

Learning to use basic LINUX commands: pwd, ls, mkdir, cd, cat, clear, cp, mv, rm, chmod and
more.
Learning to use LINUX based editor(s): vi. and Gedit

Home Assignment

Use the LINUX commands taught during the first lab assignment and show how
those commands work. You can either write or print the contents of the terminal
after using all the commands.

Day 2: Basic Problem Solving


Lab Assignment

1) Write a program to input temperatures in Celsius and Fahrenheit scale and convert the
temperatures to the other scale. Display the results.

2) Write a program that reads two values from the keyboard, swaps their values using a third
variable and prints out the result.

3) Write a program that reads two values from the keyboard, swaps their values without
using a third variable and prints out the result

Home Assignment

1) Write a program to calculate the total interest income on amount P in a period of t years.
Show the results for simple interest, compounded interest when the compounding is done
annually, semi-annually, quarterly, monthly and daily. Assume that the interest rate is r%
per year.

2) Write a program to assign the number 34.5678 to a variable named number. First display
number rounded to the nearest integer value and then display number rounded to two
decimal places.

3 Control Statements and Loops


Day 3: Control Statements (if, if-else, if-else if-else, switch-case)
Lab Assignment

1) Develop a simple calculator to accept two floating point numbers from the key-board.
Then display a menu to the user and let him/her select a mathematical operation to be
performed on those two numbers. Then display the answer. A sample run of your
program should be similar to the following:
Enter number 1: 20
Enter number 2: 12
Mathematical Operations
1 - Add
2 - Subtract
3 - Multiply
4 - Divide
Enter your preference: 2
Answer: 8.00

2) Consider a currency system in which there are notes of seven denominations, namely,
Re.1, Rs. 2, Rs.5, Rs.10, Rs. 50 and Rs. 100. If a sum of Rs. N is entered through the
keyboard, write a program to compute the smallest number of notes that will combine to
give Rs. N.

3) Write a program that reads three coordinates (x1, y1), (x2, y2) & (x3, y3) as input and
checks whether these numbers can be considered as the three vertices of a triangle. If the
vertices can form a triangle then find the type (isosceles, equilateral or right-angled) of
the triangle and the area of the triangle.

Home Assignment

1) Write a program to find the roots (real and imaginary) of the quadratic equation of the
form ax2 + bx + c = 0.

2) Write a program to input a student's score in a subject (out of hundred) and print
a grade output. Use ternary operator and no other control statement. Also for grading
purpose please use the MAKAUT grading system.

Day 4: Loops - (for, while, do-while)


Lab Assignment

1) Write a program to ask the user to enter a positive integer n value of which must be less
than 10. If the user enters an invalid input, the code repeats the statement of asking the
user for a positive integer less than 10 until the input is correct. It then prints out the sum
of the first n terms of the series: 14 + 24 + 44 + 74 + 114 + ………. .

2) A perfect number is a positive number in which sum of all positive divisors excluding
that number is equal to that number. Write a C program that accepts a positive integer
from the keyboard and checks whether the entered number is a perfect number?

3) Write a program to evaluate the summation of the following series, where the number of
terms N and independent variable X are taken as input from the user:
1X/1! +X2/2! X3/3! +………..
Home Assignment

1) The equation x2 + y2 = r2 represents a circle which centre at origin and radius r.


Write a program that reads r from the keyboard and prints the number of points with
integer coordinates that lie on the circumference of the circle.

2) Write a program to find factorial of a one digit number. What can be the potential?
Problem in finding factorial of a number larger than, say, 50?

3) Write a program to find the number of digits in a number entered through the keyboard.
Also find the sum of the digits of that number and check whether that number is a
palindrome or not.

Day 5: Loops - (for, while, do-while)


Lab Assignment

1) Fibonacci sequence is represented by 0, 1, 1, 2, 3, 5, 8, 13, 21...Construct a formula to


represent the i-th term in the series and use it to write a program to print the first n terms
of the Fibonacci sequence, where n is taken as input. NB: f(0) = 0, f(1) = 1.

2) Print the following pattern


NB: Please do not use array.

3) Write a program to print a Pascal's triangle for an input N


i.e:
Home Assignment

1) Square of 12 is 144. 21, which is the reverse of 12 has a square 441, which is same as the
reverse of 144. Write a program to find out all such numbers/pairs in the range of 10 to
100.

2) Write a program that, for all positive integers i, j, k and l from 1 through 100, finds and
prints all combinations of i, j, k and l such that i + j + k = l and i < j < k < l.

3) The equation x2 + y2 = r2 represents a circle which centre at origin and radius r. Write a
program that reads r from the keyboard and prints the number of points with integer
coordinates that lie on the circumference of the circle.

Day 6: Basics of C Functions


Lab Assignment

1) Write a menu-driven program to,


Calculate the factorial of a given number,
Check whether the number is prime or not,
Check whether the number is a palindrome or not.
Use different functions for each of the above tasks and call the functions from main(
) using switch statement.

2) A number will be provided as input along with its base (excluding hexadecimal base) and
ask from the user to which base he or she want to convert it (excluding hexadecimal
base). Write 6 separate functions for each possible conversion (it should be menu driven).

3) Write a C program to take two non-negative integers (a and b) from the user and count
the number of bits needed to be flipped to convert a to b. [Do it by using bitwise operator
and without using bitwise operator]

Home Assignment

1) The first difference D1 of a sequence A of N elements is obtained by subtracting


each element, except the last, from the next element in the array. The second
difference D2 is defined as the first difference of D1, and so on. For example, if,
A : 1, 2, 4, 7, 11, 16, 22 then
D1 : 1, 2, 3, 4, 5, 6
D2 : 1, 1, 1, 1, 1
D3 : 0, 0, 0, 0
2) Write a function findDifference( ) that takes as argument an array of n elements and
finds its first, second and third differences. Write a program to call findDifference().

3) Write functions to add, subtract and multiply two complex numbers (a + ib) and
(x + iy). Write a program to test the functions.

4) Write five user defined functions which perform the tasks of strlen( ), strcmp( ), strcpy( ),
strrev( ), strcat( ). Write a program to test these functions.
5) Write a program to find whether a matrix is symmetric or not using a function
isSymmetric( ).

4 Arrays
Day 7: One Dimensional Array (Use Separate functions to perform each task)

Lab Assignment

1) Write a program to find the max, min, average, standard deviation of the elements of an
integer array. (menu driven)

2) Write a program to insert and delete an element (given by the user) into an array in a
particular position (given by the user)

Home Assignment

1) Write a program to find the non-repeated element in an array. The array contains n
number of values where all the elements (except one) appear exactly twice.

2) Write a program to print a histogram of the frequencies of different characters present in


a character array entered through keyboard.

3) Write a program to find the largest and second largest from a set of numbers.

4.2 Day 8: Multidimensional Array (Use Separate functions to perform each task)
Lab Assignment

1) Write a program to find the transpose of a matrix.


2) Write a program to add two matrices. NB: Check proper conditions for matrix addition.
3) Write a program to accept the maximum temperature of 5 different cities in 7 days of a
week. Calculate the average temperature of each city and display the name of the cities
along with their average temperatures in order of their temperatures.

Home Assignment

1) Write a program to find whether a matrix is orthogonal or not.


2) Write a program to find whether a given matrix is upper triangular or lower triangular.

Day 9: Character Arrays/ Strings (Use Separate functions to perform each task)

Lab Assignment

1) Write a program to implement the following tasks,


 Compare two given strings,
 Concatenate two given strings, without using standard library functions.
 Whether a given string is palindrome or not
(Without using standard library functions.)

2) C Program to List All Lines containing a given String

Home Assignment

1) Write a program to read a line of text from the keyboard and convert it into a coded text
by changing its characters by adding a code number to them. This code number must be
taken as input.

2) Write a program to read in a line of text and count the number of blank spaces, tabs and
new lines in that line. Also rewrite the line of text with tabs and new lines replaced by the
visible sequences ‘\t’ ‘\n’
3) Write a program to read in a line of text and count the number of lines, words and
characters in that text.
4) Write a program to count the number of vowels and digits in a given string.

Day 10: Recursive Functions


Lab Assignment
1) Write a recursive function to calculate the GCD (greatest common divisor) / HCF
(Highest common factor) of two numbers.
2) Write a recursive function to print the first n Fibonacci numbers.
3) Write a program to obtain the reverse of a given integer using recursion.

Home Assignment

1) Write a recursive function to evaluate n Cr


2) Write a recursive function to convert a decimal integer, taken as input, to its hexadecimal
equivalent.
3) Find the maximum and minimum of a list of numbers using a recursive function.
4) Write a recursive function to calculate the sum of all digits of a number entered by the
user.

6 Advanced Topics
Day 11: Pointers
Lab Assignment
1) Write a program to sort a list of elements, using pointers and dynamic memory allocation.
2) Write a program, using pointers, to multiply two matrices. NB: Check proper conditions
for matrix multiplication.

Home Assignment

1) Write an interactive C program, using pointers, which will encode a line of text. To
encode a line of text, proceed as follows:
 Convert each character, including blank spaces, to its ASCII equivalent
 Generate a positive random integer. Add this integer to the ASCII equivalent of each
character. The same random integer will be used for the entire line of text
 Suppose that N1 represents the lowest permissible value in the ASCII code, and N2
represents the highest permissible value. If the number obtained in step 2 above (i.e.,
the original ASCII equivalent plus the random integer) exceeds N2, then subtract the
largest possible multiple of N2 from this number, and add the remainder to N1. Hence
the encoded number will always fall between N1 and N2, and will therefore always
represent some ASCII character.
 Display the characters that correspond to the encoded ASCII values.

2) Write a program, using pointers, that accepts a string and converts all its characters to
upper or lower case. Use the functions toupper( ) and tolower( ) defined in ctype.h.

3) Write three functions, using pointers, to concatenate two strings, to compare two strings
and to reverse a string, respectively. Test these functions in a complete program.

Day 12: Structures and Unions and Files


Lab Assignment

1) Write a function findMaxMin() in to find both the maximum and minimum of a set of
integers stored in an array. The function takes two arguments: the size of the array and
and the array.

2) Define a structure named student to store information of a student (roll, name,


marksInPhysics, marksInChemistry, marksInMathematics). Write a program, which will
take as input the roll, name and numbers obtained by several students in different
subjects. The program will calculate the total marks obtained by each student and display
the list of students in descending order according to the total marks

3) Define a structure named employee to store information of an employee (empNo, name,


department, basicPay, DA, HRA and grossSalary). Write a program, which will take as
input the empNo, name, department, basicPay for several employees from a file named
I_P.txt. The program will calculate the DA, HRA and total for each employee and
display the details of the employee having the highest gross salary in a file O_P.txt.

Home Assignment

1) Write a program by using structure that describes the set of books in a library. For each
book the members are name of author, publisher, price and branch information. The
program should,
 print the list of books supplied by a publisher
 print the list of books in a particular branch
in a file say “lib.txt”

2) Develop a simple telephone directory which saves your friends contact information in a
file named directory.txt. The program should have a menu similar to the following:
Menu
1 - Add new friend.
2 - Display contact info.
3 - Exit.
Enter your preference:
 When you press 1 it should request you to enter the following data:
New friend info
Name: Saman
Phone no.: 011-2123456
e-mail: [email protected]
After adding new contact information it should again display the menu.
 When you press 2 it should display all the contact information stored in the
directory.txt file as follows:

Contact Info

Name Phone No. E-mail


Kamala 033-9876543 [email protected]
Avinash 022-8765432 [email protected]
Saman 011-2123456 [email protected]

You might also like