Problem Solving and Programming With C 12 September 2021 With Lab Exercises
Problem Solving and Programming With C 12 September 2021 With Lab Exercises
L T P C
0 0 6 3
The course is designed to enable the student to write programs for problem solving. After an introduction to
program logic design using algorithms and flowcharts, converting the logic into programs is taught. The
features of structured programming are explained with the C programming language as an example. This
course lays the foundation both for developing program logic and for writing programs in C according to the
developed logic.
Course objectives:
1.Familiarize the student with the steps involved in writing and running a compiled program.
2.Enable the student to build program logic with algorithms and flowcharts.
3. Explain with the features and constructs of C programming such as data types, expressions, loops,
functions, arrays, pointers, and files.
4.Demonstrate the handling of variables and input-output operations in C.
5.Train the student to convert program logic into C language code using a top-down approach.
A
BB
C CC
DDDD
E E E EE
1
23
456
7 8 9 10
Calculate the greatest common divisor of two numbers
Generate first n numbers in the Fibonacci series
Generate n prime numbers
Swap two numbers using pointers.
Performs all the five arithmetic operations using Pointers.
Learning Outcomes:
After completion of this unit the student will be able to
● Construct C programs using various conditional statements (L3).
● Develop C programs using loops and nested loops (L6).
● Demonstrate the usage of pointers (L3).
Learning Outcomes:
After completion of this unit the student will be able to
understand the concept of subprograms and recursion (L2).
apply the in-built functions to develop custom functions for solving problems (L3).
make use of parameter passing mechanisms (L3).
infer the effect of storage classes on variables (L2).
Learning Outcomes:
After completion of this unit the student will be able to
develop programs for storing and managing collections of items using arrays (L3).
make use of the in-built functions to manipulate strings (L3).
solve problems related to arrays and strings (L3).
Learning Outcomes:
After completion of this unit, the student will be able to:
develop programs using structures and unions for storing dissimilar data items (L6).
compare the utilization of memory by structures and unions (L5).
make use of files and file operations to store and retrieve data (L3).
Text Books(s)
B. A. Forouzan and R. F. Gilberg, Computer Science: A Structured Programming
Approach Using C, 3/e, Cengage Learning
Reference Book(s)
Jeri R Hanly, Elliot B Koffman, Problem Solving and Program Design in C, 7/e,
Pearson Education, 2012.
B.W. Kernighan and Dennis M. Ritchie, The C Programming Language, 2/E, Pearson
education, 2015.
B. Gottfried, Programming with C, 3/e, Schaum’s outlines, McGraw Hill (India),
2017.
P. Dey and M Ghosh, Programming in C, 2/e, Oxford University Press, 2011.
Course Outcomes:
After completion of this course the student will be able to
• Build logic for solving a problem and translate it into a program. (L3).
• Define variables and construct expressions using C language (L1).
• Utilize arrays, structures and unions for storing and manipulating data (L3).
• Develop efficient, modular programs using functions (L3).
• Write programs to store and retrieve data using files (L3).
Additional Exercises:
• Given numbers x, y, and target, return whichever of x and y is closer to the target. If they have
the same distance, return the smaller of the two
• There are three friends Ram, Raheem and Robert. Ram’s age is 20, Raheem is aged three times
more than his friend Ram. After 8 years, he would be two and a half times of Ram’s age. After
further 8 years, how many times would he be of Rams age? Robert’s age is 25 now. Now program
your computer to determine the final ages of all the three people after 16 years and also show
who is elder.
• Given an actual time and an alarm clock time, both in “military” format (such as 0730 for
7:30am), print how many more minutes before the alarm rings. But if the time is after the
alarm, print "Alarm already went off".
• Let there be a scenario where you and your friend are going to a restaurant. You have lunch
there every fourth day, and he has his lunch there every sixth day. How many days before you
meet again for lunch at the same restaurant?
• Two friends Suresh and Ramesh have m red candies and n green candies respectively. They want
to arrange the candies in such a way that each row contains equal number of candies and also
each row should have only red candies or green candies. Help them to arrange the candies in
such a way that there are maximum number of candies in each row.
• On a chessboard, positions are marked with a letter between a and h for the column and a
number between 1 and 8 for the row. Given two position strings, return true if they have the
same colour.
• Given two strings s0 and s1, return whether they are anagrams of each other.
• Write a program to encrypt and decrypt a password which is alphanumeric
• Given a string, return the string with the first and second half swapped. If the string has odd
length, leave the middle character in place.
• Given an array of integers, return the second-largest element.
• Given lists of integers people, jobs, profits. Each person i in people have people[i] amount of
strength, and performing job j requires jobs[j] amount of strength and nets profits[j] amount of
profit. Given that each person can perform at most one job, although a job can be assigned to
more than one person, return the maximum amount of profit that can be attained.
• Mr. Roxy has arranged a party at his house on the New Year’s Eve. He has invited all his friends -
both men and women (men in more number). Your task is to generate the number of ways in
which the invitees stand in a line so that no two women stand next to each other. Note that the
number of men is more than the number of women and Roxy doesn’t invite more than 20
guests. If there are more than 20 guests or an arrangement as per the given constraints is not
possible, print ‘invalid’.
• Two friends have entered their date of birth and they want to know who is elder among
them. Make a structure named Date to store the elements day, month and year to store
the dates.
Case Study:
• 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 functions can be done: Display book information, Add a new book, Display all
the books in the library of a particular author, Display the number of books of a
particular title, Display the total number of books in the library, 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)
• Ranjan is maintaining a store. Whenever a customer purchases from the store, a bill is
generated. Record the customer name, amount due, the amount paid, mobile number
with purchased items in file. At the end of day print the total income generated by store.
• Contact Management System- Create structure to store Contact information like
name,gender,mail,phone number and address. Users can add new contact and can
also edit and delete existing contact. (Hint: Use Files to store data)