Lab and Home Assignment Sheet - 2022
Lab and Home Assignment Sheet - 2022
Name: ......................................................................
Roll: ......................................................................
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.
Evaluation procedure
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.
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.
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.
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:
1X/1! +X2/2! X3/3! +………..
Home Assignment
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.
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.
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
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.
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
Home Assignment
Day 9: Character Arrays/ Strings (Use Separate functions to perform each task)
Lab Assignment
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.
Home Assignment
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.
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.
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