ACADEMY OF TECHNOLOGY
Lab Assignment
Subject: Programming for problem solving Discipline: B – Tech (All)
Subject Code: ES-CS291 Semester: 2nd
Assignment – 1
The objective of this assignment is to learn how to write C program using Input/output
Function and conditional statements using:
(a) ‘if else’ condition
(b) ‘if else if’ condition and how to use logical operators.
(c) ‘switch case’ statement
Assignment:
1. Write a C program to enter two numbers and find their sum.
2. Write a C program to enter two numbers and perform all arithmetic operations (+, -, *, / and
%)
3. Write a C program to enter length and breadth of a rectangle and radius of a circle. Find
perimeter and area of rectangle and circumference and area of circle.
4. Write a C program to swap two numbers. (with and without third variable)
5. Write a C program to find maximum between three numbers using nested if-else.
6. Write a C program to check whether a number is even or odd using if-else statement.
7. Write a C program to check whether year is leap year or not.
8. Write a C program to find all roots of a quadratic equation 𝑎𝑥 2 + 𝑏𝑥 + 𝑐 = 0 for all possible
combination of a, b and c.
A quadratic equation will have two roots which are obtained using the following expression
−𝑏±√𝑏2 −4𝑎𝑐
𝑋= where 𝑏 2 − 4𝑎𝑐 is called discriminate.
2𝑎
Note:
When, 𝑏 2 − 4𝑎𝑐 > 0 roots are real and unequal.
𝑏
𝑏 2 − 4𝑎𝑐 = 0 roots are real and equal 𝑖. 𝑒. 𝑥 = − 2𝑎 .
𝑏 √𝑏 2 −4𝑎𝑐
𝑏 2 − 4𝑎𝑐 < 0 roots are imaginary 𝑖. 𝑒. 𝑥 = − ± ∗ 𝑖.
2𝑎 2𝑎
Practice:
1. Mr. Sayan Ghosh is an employee of a Private Firm. His Basic is Rs. 5500/-. Now the dearness
allowance is 74% of his basic salary and house rent allowance is 15% of basic salary. Write
a program to calculate his gross salary. [Though his basic salary is given, do this program
where basic is taken through keyboard].
2. The length and breadth of a rectangle and radius of a circle are input through keyboard.
Write a program to calculate the area and perimeter of the rectangle, and the area and the
circumference of the circle.
3. Write a C program to find area of a triangle Area of triangle=
𝑎+𝑏+𝑐
√𝒔(𝒔 − 𝒂)(𝒔 − 𝒃)(𝒔 − 𝒄) .Where a, b and c are three sides of the triangle and 𝑠 = .
2
4. Write a C program to calculate and print electricity bill for consumer @Rs.3.75 per unit, given
the following information: previous meter reading and current reading.
ACADEMY OF TECHNOLOGY | Lab Assignment
ACADEMY OF TECHNOLOGY
Lab Assignment
Subject: Programming for problem solving Discipline: B – Tech (All)
Subject Code: ES-CS291 Semester: 2nd
Assignment – 2 (Continue Assignment – 1)
Assignment:
1. Write a C program to check whether an alphabet is vowel or consonant using switch case.
2. Write a C program to check whether a number is positive, negative or zero using switch case.
3. Write a C program to calculate the value of 𝑌 using:
𝑌(𝑥, 𝑛) = {1 + 𝑥 2 𝑤ℎ𝑒𝑛 𝑛 = 1
𝑥
= {1 + 𝑤ℎ𝑒𝑛 𝑛 = 2
𝑛
= {1 + 2𝑥 𝑤ℎ𝑒𝑛 𝑛 = 3
= {1 + 𝑛𝑥 𝑤ℎ𝑒𝑛 𝑛 > 3 𝑜𝑟 𝑛 < 1
Where 𝑥 and 𝑛 are user inputs. Do this program using if-else-if statement and switch case
statement.
4. Write a C program to find maximum between three numbers using logical operator and
ternary operator.
Practice:
1. Write a C Program for following…
An electric distribution companies arranges its domestic consumer as follows:
Consumption in Units Rate of charge
0 – 200 Rs. 0.50 per unit
201 - 400 Rs. 100 plus Rs. 0.65 per unit excess to 200
400 - 600 Rs. 250 plus Rs. 0.80 per unit excess to 400
Above 600 Rs. 425 plus Rs. 1.25 per unit excess to 600
Print the amount to be paid by consumer.
2. Write a C program to check whether a number is even or odd using switch-case statement
3. Write a C program to create Simple Calculator using switch case.
4. Write a C program to find maximum between two numbers using switch case.
5. A student’s grade is calculated in a subject according to the following rules:
Number Obtained Grade
>=90 and <=100 O
>=80 and <90 E
>=70 and <80 A
>=60 and <70 B
>=50 and <60 C
>=40 and <50 D
<40 and >=0 F(FAILED)
Others No. INVALID
Write a C Program which accept a student’s marks as an input and then determine the grade
of the students in that subject. Do this program using ‘if-else-if’ statement and ‘switch-case’
statement.
ACADEMY OF TECHNOLOGY | Lab Assignment
ACADEMY OF TECHNOLOGY
Lab Assignment
Subject: Programming for problem solving Discipline: B – Tech (All)
Subject Code: ES-CS291 Semester: 2nd
Assignment – 3
The objective of this assignment is to learn how to write how to write a loop statement
using:
(a) ‘while’ loop.
(b) ‘do while’ loop.
(c) ‘for’ loop.
Assignment:
1. Write a C program to print natural numbers from 1 to n and also print their sum.
2. Write a C program to check whether a number is palindrome or not
3. Write a C program to find all factors of a number.
4. Write a C program to calculate factorial of a number
5. Write a C program to find HCF (GCD) and LCM of two numbers.
6. Write a C program to check whether a number is Prime number or not.
7. Write a C program to print all Prime numbers between 1 to n.
8. Write a C program to check whether a number is Armstrong number or not.
9. Write a C program to check whether a number is Perfect number or not.
10. Write a C program to check whether a number is Strong number or not.
11. Write a C program to print Fibonacci series up to n terms.
12. Write a C program to find value of following series:
1 1 1
y = 1 + 2 + 3 + ⋯ + n where 𝑛 is user input.
𝑥3 𝑥5 𝑥7 𝑥𝑛
13. Write a C program to find value of 𝑠𝑖𝑛 series. (𝑖. 𝑒. 𝑦 = 𝑥 − + − + ⋯+ )
3! 5! 7! 𝑛!
Practice:
1. Write a C program to swap first and last digits of a number.
2. Write a C program to count number of digits in a number and also their sum and product.
3. Write a C program to print multiplication table of any number.
4. Write a C program to print all alphabets from a to z
5. Write a C program to print all odd and even numbers between 1 to n and also print their
sum.
6. Write a C program to find all prime factors of a number.
7. Write a C program to find value of following series:
22 32 n2
y=1+ + + ⋯+ where 𝑛 is user input.
2! 3! n!
8. Write a C program to find power of a number using for loop.
9. Write a C program to print all Armstrong numbers between 1 to n.
10. Write a C program to print all Perfect numbers between 1 to n.
11. Write a C program to print all Strong numbers between 1 to n.
𝑥2 𝑥4 𝑥6 𝑥𝑛
12. Write a C program to find value of 𝑐𝑜𝑠 series. (𝑖. 𝑒. 𝑦 = 1 − + − +⋯+ )
2! 4! 6! 𝑛!
13. Write a C program to print Fibonacci series with in a certain range.
14. Write a C program to convert binary to decimal number and decimal to binary number.
ACADEMY OF TECHNOLOGY | Lab Assignment
ACADEMY OF TECHNOLOGY
Lab Assignment
Subject: Programming for problem solving Discipline: B – Tech (All)
Subject Code: ES-CS291 Semester: 2nd
Assignment – 4 (Continue Assignment – 3)
Assignment:
1. Write a C program to print the following asterisk graph:
*
* *
* * *
* * * * (Up to n numbers of row)
2. Write a C program to print the following pattern:
1
2 3
4 5 6
7 8 9 10 (Up to n numbers of row)
3. Write a C program to print the following pattern:
1
2 3
3 4 5
4 5 6 7 (Up to n numbers of row.)
4. Write a C program to print digits in following pyramidal form:
1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4 (Up to n numbers of row)
5. Write a C program to print the following pascal triangle
1
1 1
1 2 1
1 3 3 1 (Up to n numbers of row)
Practice:
1. Write a C program for the all following patterns (No row is user input):
i) ii) iii) iv)
A D D D D A A *
B C C C C A B B A * * *
C D E B B A B C C B A * * * * *
D E F G A A B C D C B A * * * * * * *
v) vi) vii) viii)
1 10 9 8 7 D C B A 1 0 1
0 1 6 5 4 C B A 0 1 0
1 0 1 3 2 B A 1 0 1
0 1 0 1 1 A
ACADEMY OF TECHNOLOGY | Lab Assignment
ACADEMY OF TECHNOLOGY
Lab Assignment
Subject: Programming for problem solving Discipline: B – Tech (All)
Subject Code: ES-CS291 Semester: 2nd
Assignment – 5
The objective of this assignment is to learn how to use array in the program
(a) Both 1 – D and 2 – d array
Assignment:
1. Write a C program to find the sum of all elements of an array.
2. Write a C program to insert and delete an element from the any position of an array.
3. Write a C program to sort the all elements of an array in ascending order using bubble sort
technique.
4. Write a C program to sort the all elements of an array in ascending order using selection
sort technique.
5. Write a C program to search the any elements from an array using linear search technique.
Practice:
1. Write a C program to calculate the sum of all negative and positive elements in an array.
2. Write a C program to find maximum and minimum element in an array (without sorting).
3. Write a C program to find the second largest element from an array (without sorting).
4. Write a C program to find the arithmetic mean, variance and standard deviation of any 𝑛
values.
1 1 2
Mean (μ) = n ∑ni=1 xi Varianc(ϑ) = (μ) = n ∑ni=1(xi − μ)
Standard deviation(σ) = √ϑ
5. Write a C program to search the any elements from an array using binary search technique.
6. Write a C program to sort the all elements of an array in ascending order using modified
bubble sort technique.
7. Write a C program to sort the all elements of an array in ascending order using insertion sort
technique.
8. Write a C program to check the frequency of each elements in an array.
9. Write a C program to delete all duplicate elements from an array.
10. Write a C program to left rotate and right rotate an array.
Assignment – 6 (Continue Assignment – 5)
Assignment:
1. Write a C program to add two matrices of order M × N
2. Write a C program to multiply two matrices.
3. Write a C program to find transpose of a matrix.
Practice:
1. Write a C program to subtract two matrices.
2. Write a C program to perform Scalar matrix multiplication.
3. Write a C program to find sum of main diagonal and minor diagonal elements of a matrix.
4. Write a C program to find sum of each row and column of a matrix.
5. Write a C program to find upper triangular matrix and lower triangular matrix.
6. Write a C program to check Identity matrix.
7. Write a C program to check Symmetric matrix.
8. Write a C program to check Sparse matrix.
ACADEMY OF TECHNOLOGY | Lab Assignment
ACADEMY OF TECHNOLOGY
Lab Assignment
Subject: Programming for problem solving Discipline: B – Tech (All)
Subject Code: ES-CS291 Semester: 2nd
Assignment – 7
The objective of this assignment is to learn how to use string in the program
[Do the all programs using library function and without using library function]
Assignment:
1. Write a C program to find length of a string.
2. Write a C program to count total number of vowels and consonants in a string.
3. Write a C program to concatenate two strings.
4. Write a C program to find reverse of a string.
5. Write a C program to check whether a string is palindrome or not (using single string only).
6. Write a C program to find total number of alphabets, digits or special character in a string.
Practice:
1. Write a C program to compare two strings.
2. Write a C program to convert lowercase string to uppercase string and vice versa.
3. Write a C program to find highest and lowest frequency character in a string.
4. Write a C program to count frequency of each character in a string.
5. Write a C program to trim both leading and trailing white space characters from given
string.
6. Write a C program to remove all extra blank spaces from given string.
7. Write a C Program to count lines, words and characters in a text.
8. Write a C Program to read an array of names and to set them in alphabetical order
Assignment – 8
The objective of this assignment is to learn how to use user define function in the program
Assignment:
1. Write a C program to find the factorial of a number and also find the value of 𝑛 𝐶𝑟 using this
function.
2. Write a C Program to count the frequency of array elements in a 1-D array
3. Write a C Program to find the sum of two matrices using function.
4. Write a C program to find power of any number using recursive function.
5. Write a C program to find the GCD of two numbers using recursive function, and also find
the GCD of three numbers using this function.
6. Write a C program to find the Fibonacci series up to n term using recursive function
Practice:
1. Write a C program to find maximum and minimum elements in array using recursive function.
2. Write a C program to sort the all elements of an array in ascending order using marge sort
technique.
3. Write a C program to sort the all elements of an array in ascending order using quick sort
technique.
4. Write a C program to solve Tower of Hanoi problem
[NOTE: Implement the previous assignments using function call]
ACADEMY OF TECHNOLOGY | Lab Assignment
ACADEMY OF TECHNOLOGY
Lab Assignment
Subject: Programming for problem solving Discipline: B – Tech (All)
Subject Code: ES-CS291 Semester: 2nd
Assignment – 9
The objective of this assignment is to learn how to use pointer in the program
Assignment:
1. Write a C Program using pointer to find the bigger of two given numbers.
2. Write a C Program to swap two given numbers using call by reference.
3. Write a C program to copy one array to another using pointers.
4. Write a C program to reverse an array using pointers.
5. Write a C program to add two matrix using pointers.
Practice:
1. Write a C program to copy one string to another using pointers.
2. Write a C program to concatenate two strings using pointers.
3. Write a C program to sort an array using pointers (Any technique).
4. Write a C program to search an element in array using pointers.
[NOTE: Implement the previous assignments using pointer and function]
Assignment – 10
The objective of this assignment is to learn how we can use Structures and Unions and also
how-to dynamic memory allocation happen in C Program.
Assignment:
1. Write a program to store and print the roll no., name, age and marks of a student using
structures.
2. Write a program to store the roll no. (starting from 1), name and age of 5 students and then
print the details of the student with roll no. 2.
3. Write a program to store and print the roll no., name, age, address and marks of 15 students
using structure.
4. Write a program to add two distances in inch-feet using structure. The values of the
distances is to be taken from the user.
5. Enter the marks of 5 students in Chemistry, Mathematics and Physics (each out of 100) using
a structure named Marks having elements roll no., name, chem_marks, maths_marks and
phy_marks and then display the percentage of each student.
6. Write a program to add, subtract and multiply two complex numbers using structures to
function.
7. Define a union with the following three members: roll no, name and total marks of student.
Write a c program to read and display the details of a student.
8. C Program to Find Largest Number from an array. Array must be declared using Dynamic
Memory Allocation.
Practice:
1. Write a structure to store the roll no., name, age (between 11 to 14) and address of students
(more than 10). Store the information of the students.
1-Write a function to print the names of all the students having age 14.
2-Write another function to print the names of all the students having even roll no.
3-Write another function to display the details of the student whose roll no is given (i.e. roll
no. entered by the user).
2. Write a structure to store the name, account number and balance of customers (more than
10) and store their information.
1- Write a function to print the names of all the customers having balance less than $200.
2-Write a function to add $100 in the balance of all the customers having more than $1000
in their balance and then print the incremented value of their balance.
ACADEMY OF TECHNOLOGY | Lab Assignment
ACADEMY OF TECHNOLOGY
Lab Assignment
Subject: Programming for problem solving Discipline: B – Tech (All)
Subject Code: ES-CS291 Semester: 2nd
3. Write a program to compare two dates entered by user. Make a structure named Date to
store the elements day, month and year to store the dates. If the dates are equal, display
“Dates are equal” otherwise display “Dates are not equal”.
4. Write a structure to store the names, salary and hours of work per day of 10 employees in a
company. Write a program to increase the salary depending on the number of hours of work
per day as follows and then print the name of all the employees along with their final
salaries.
Hours of work per day 8 10 >=12
Increase in salary $50 $100 $150
5. Let us work on the menu of a library. Create a structure containing book information like
accession number, name of author, book title and flag to know whether book is issued or not.
Create a menu in which the following can be done.
1 - Display book information
2 - Add a new book
3 - Display all the books in the library of a particular author
4 - Display the number of books of a particular title
5 - Display the total number of books in the library
6 - Issue a book
(If we issue a book, then its number gets decreased by 1 and if we add a book, its number
gets increased by 1)
Assignment – 11
The objective of this assignment is to learn how to solve numerical method problems,
namely root finding of function, differentiation of function and simple integration.
Assignment:
1. Consider the equation 𝑓(𝑥) = 𝑥 3 + 3𝑥 – 5 . Implement bisection method to find out the
root.
2. Consider the equation 𝑓(𝑥) = 𝑥 3 + 3𝑥 – 5 . Implement Regula-falsi method to find out the
root.
1
3. Consider the equation 𝑓(𝑥) = 1 + 𝑥2 . Implement trapezoidal method to calculate definite
integral.
Practice:
1. Consider the equation 𝑓(𝑥) = 𝑥 3 + 3𝑥 – 5 . Implement Newton Raphson method to find
out the root.
1
2. Implement Simpson’s method to calculate definite integral of the above equation.
3
ACADEMY OF TECHNOLOGY | Lab Assignment
ACADEMY OF TECHNOLOGY
Lab Assignment
Subject: Programming for problem solving Discipline: B – Tech (All)
Subject Code: ES-CS291 Semester: 2nd
Assignment – 12
The objective of this assignment is to learn how we can demonstrate File concepts in C.
Assignment:
1. Write a C Program to create a text file (check read, write, append mode).
2. Write a C Program to read the text file. Create in program 1 and also count the number of
vowels present in a file.
3. Write a C Program to copy the content of the file to another file.
Practice:
1. A file called “STUDENT.DAT” contains information such as student roll no, name and total
marks. Write a C Program to create a file to store details of n students using structure also.
2. Write a C Program to read information from a file “STUDENT.DAT” which is created before.
Also display the list of students who have scored 75 marks and above.
3. Write a C Program to read data file containing integers. Find the largest and smallest
integers and display them.
Assignment – 13
The objective of this assignment is to learn how we can demonstrate Command line
argument concepts in C.
Assignment:
1. Write a C program to find sum of three numbers inputted by command line argument.
2. Write a C program to find largest number among three numbers inputted by command line
argument.
Practice:
1. Write a C program to check whether a number is even or odd, inputted by command line
argument.
2. Write a C program to find factorial of given positive integer inputted by command line
argument.
3. Write a C program to check an inputted value by command line argument is correct number
or not (i.e. 123, -1234, 1.20 all are valid. --12, 1-+2, 1.2.2 1asd2 all are invalid).
ACADEMY OF TECHNOLOGY | Lab Assignment