You are on page 1of 49

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

COURSE CODE : 18CS101

COURSE TITLE : C PROGRAMMING FOR PROBLEM SOLVING

FACULTY NAME : Ms.KALPANA P.


18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

SRI KRISHNA COLLEGE OF TECHNOLOGY

Vision
Sri Krishna College of Technology aspires to be recognized as one of the
pioneers in imparting world class technical education through Technology
enabled Innovative Teaching Learning Processes with a focus on research
activities to cater the societal needs.
Mission
1. To be recognized as centre of excellence in science, engineering and
technology through effective teaching and learning processes by providing
a conducive learning environment
2. To foster research and development with creative and entrepreneurial
skills by means of innovative applications of technology
3. Accomplish expectations of the society and industry by nurturing the
students to be competent professionals with integrity

2
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Vision
The department of CSE fosters a conducive ambience to meet the global
standards by equipping the students with modern techniques in the area
of Computer Science and relevant research to address the societal needs.

Mission
1.To provide quality academic environment that would help the students
to acquire knowledge in computer science concepts.
2.To motivate faculty to disseminate knowledge to different levels.
3.To produce competent graduates who can develop algorithms and
systems to the target groups.

3
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

PROGRAMME EDUCATIONAL OUTCOMES (PEOs)

PEO1. To provide students with a solid foundation in mathematical,


scientific and engineering fundamentals required to solve computer
science and engineering problems.
PEO2. To provide the students scope to improve programming skills,
apply computing techniques to design and maintain hardware and
software with social relevance.
PEO3. To provide the students, the ability to adapt, contribute and
innovate new technologies in the key domains of Computer Science and
Engineering and to productively extend their interest by pursuing higher
studies and research.
PEO4. To inculcate in students’ professional and ethical attitude,
entrepreneurship skills, effective communication skills and team work
skills to work in multidisciplinary teams.

4
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

PROGRAMME OUTCOMES (POs)


PO1 Engineering knowledge
Apply the knowledge of mathematics, science, engineering fundamentals, and an
engineering specialization to the solution of complex engineering problems.
PO2 Problem analysis
Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
PO3 Design/Development of solutions
Design solutions for complex engineering problems and design system
components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and
environmental considerations.
PO4 Conduct investigations of complex problems
Use research-based knowledge and research methods including design of
experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.

5
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

PROGRAMME OUTCOMES (POs)

PO5 Modern tool usage


Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
PO6 The engineer and society
Apply reasoning informed by the contextual knowledge to assess societal, health,
safety, legal and cultural issues and the consequent responsibilities relevant to
the professional engineering practice.
PO7 Environment and sustainability
Understand the impact of the professional engineering solutions in societal and
environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.
PO8 Ethics
Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice

Module 1 6
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

PROGRAMME OUTCOMES (POs)

PO9 Individual and team work


Function effectively as an individual, and as a member or leader in diverse teams,
and in multidisciplinary settings.
PO10 Communication
Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and
write effective reports and design documentation, make effective presentations,
and give and receive clear instructions.
PO11 Project management and finance
Demonstrate knowledge and understanding of the engineering and management
principles and apply these to one’s own work, as a member and leader in a team,
to manage projects and in multidisciplinary environments.
PO12 Life-long learning
Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological
change.

7
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

PROGRAMME SPECIFIC OUTCOMES (PSOs)

Graduates of CSE program of Sri Krishna College of Technology will demonstrate

PSO1 Professional Skills


Deep understanding of the basic concepts in Computer Science domain.

PSO2 Problem Solving Skills


Ability to develop programming skills and solve problems.

PSO3 Successful career and entrepreneurship


Help the student to develop algorithms and computer systems of high standards
and become entrepreneurs.

8
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Course code and title :18CS101 – C PROGRAMMING FOR PROBLEM SOLVING


Regulation : R2018
Core / Elective : Core
Course objectives:
• To understand problem solving concepts.
• To gain knowledge about the control structures in C
• To use arrays and functions in C
• To apply pointers to arrays, strings and pass pointers to functions in C
• To gain knowledge about structures and pointer to structures.
• To develop the ability to apply file I/O operations.
Course Outcomes:
CO1 Apply problems solving techniques to real world problems. [AP]
CO2 Design programs using fundamental C constructs. [U]
CO3 Use the concepts of pointers , arrays and structures in programs [AP]
CO4 Do modular programming with functions [U]
CO5 Illustrate file access. [AP]
CO6 Demonstrate and apply the pre-processor commands and bitwise
operations in C [AP]

9
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING
Course Contents

Problem Solving Techniques: General problem Solving concepts-: Algorithm,


Pseudo-code and Flowchart Problem Solving with Sequential Logic Structure -
Problem Solving with Decisions - Problem Solving with Loops C Programming : C
Character Set – Identifiers and Keywords – Data Types - Constants Variables and
Arrays-Declarations-Operators and Expressions - Data input and output
Branching: if-else Looping: while-do while-for nested control structures -switch-
break-continue-goto. Arrays: Defining an array- Processing an array- Multi
dimensional arrays Strings: Defining a string-Null character-initialization of strings
– reading and writing a string- processing the string Functions and Structures:
Defining a Function – Accessing a function – Function Prototypes Passing
arguments to a function – Recursion. Structures- Defining a structure –
processing a structure – nested structure-Self -referential Structure. Pointers:
Pointers - pointers to array - Pointer and functions-Pointer to strings – Array of
pointers –pointers to pointers- Pointer to structures - Dynamic memory allocation –
Introduction to Unions. Files: File I/O operations – Error Handling During I/O
Operations –Binary files- Random Access to Files -Bitwise Operators-Pre-
processor Commands- Command Line Arguments

Module 1 10
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING
Text Books

1. M. Sprankle, “Problem Solving and Programming Concepts”, 9th Edition, Pearson


Education, New Delhi, 2011.
2. Byron, S. Gottfreid, “Programming with C”, Tata McGraw Hill, Schaum’s outlines, 3rd Edition,
2014.
3. R. G. Dromey, “How to Solve it By Computer”, Pearson , 1st edition, 2007.

Reference Books
1. Herbert Schildt, “The Complete Reference C”, 4th edition ,TMH,2015.
2. S.ThamaraiSelvi and R.Murugesan, “Test your skills in C”, 6E, TMH, 2012.
3. K.R.Venugopal and SudeepR.Prasad , “Mastering C”, TMH ,Second edition , 2015
4. YashwantKanetkar, “Let us C”, 12th Edition, BPB Publications, 2014
5. B Stephen G. Kochan “Programming in C”,Fourthedition, Addison Wesley publishing,2014.
6. Behrouz A. Forouzan& Richard F. Gilberg, “A Structured Programming Approach Using C”,
3E, Cengage Learning, 2008
7. E Balagurusamy, “Programming in ANSI C”, 6E, TMH, 2012.,”Computer System
Architecture”,3rdEdition, Pearson Education, 2007
8. Yashavant Kanetkar, “Understanding Pointer in C”, 3E, BPB Publication, 2011.

11
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING
Web References:

1. https://www.codeguru.com/
2. http://raptor.martincarlisle.com/
3. https://scratch.mit.edu/
4. https://www.tutorialspoint.com/cprogramming/cprogramming_tutorial.pdf
5. http://students.iitk.ac.in/programmingclub/course/#notes
Assessment Methods & Levels (based on Blooms’ Taxonomy)
Summative assessment based on Continuous and End Semester Examination
Continuous Assessment End
Theory Practical Semester
Bloom’s Level Term End Rubric Examination
CIA1 CIA2
Assessment based CIA (Theory)
[6 marks] [6 marks]
[8 marks] [40 Marks] [40 marks]
Remember 30 30 20 - 20
Understand 40 30 30 30 30
Apply 30 40 50 70 50
Analyse - - - - -
Evaluate - - - - -
Create - - - - -

12
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Module 1
Problem Solving Techniques

Problem Solving Techniques: General problem Solving concepts-: Algorithm,


Pseudo-code and Flowchart Problem Solving with Sequential Logic Structure -
Problem Solving with Decisions - Problem Solving with Loops

CO1 : Apply problems solving techniques to real world problems. RBT : AP

Module 1 13
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Module 1
Session 1 : General problem Solving concepts-: Algorithm

Session 2 :
General problem Solving concepts-: Pseudo-code and
Flowchart

Problem Solving with Sequential Logic structure,


Session 3 :
Decisions, Loops

Module 1 Session 1 14
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Session 1
General problem Solving concepts-:
Algorithm

Learning • To understand problem solving


Objective concepts.

Module 1 Session 1 15
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Outline

 What is problem solving?


 Problem Solving phases
 Algorithm
 Characteristics of algorithm
 Factors affecting algorithm
 Advantage & disadvantage

Module 1 Session 1 16
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Problem Solving
Outline Outline In Everyday Life

• People make decisions every day to solve problems that affect


their lives.

• The problems may be unimportant.

• If a bad decision is made, time and resources are wasted, so


it’s important that people know how to make decisions well.

• There are six steps to follow to ensure the best decision.

Module 1 Session 1 17
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Outline

18

Module 1 Session 1 18
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline
Problem Solving-
Outline
SIX Steps
1. Identify the problem.
2. Understand the problem.
3. Identify alternative ways to solve the problem.
4. Select the best way to solve the problem from the list of
alternative solutions.
5. List instructions that enable you to solve the problem using
the selected solution.
6. Evaluate the solution.

Module 1 Session 1 19
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Outline

Module 1 Session 1 20
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline ProblemOutline
Statement

• Collect and analyze information and data

• Talk with people familiar with the problem

• If at all possible, view the problem first hand

• Confirm all findings

Module 1 Session 1 21
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Outline
TYPES OF PROBLEM SOLUTIONS

Algorithmic
solutions Heuristic
solutions

Module 1 Session 1 22
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

• Problems
Outline do not always have straightforward solutions.
Outline
 Algorithmic solutions
• Some problems can be solved with a series of actions.
• Once the alternatives have been eliminated, the solution can
be reached by completing the actions in steps

 Heuristic solutions
• The solutions of other problems are not so straightforward.
• These solutions require reasoning built on knowledge and
experience, and a process of trial and error.

Module 1 Session 1 23
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Outline

Module 1 Session 1 24
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

PROBLEM
Outline SOLVING WITH COMPUTERS
Outline

• Solution means the instructions listed during step 5 of


problem solving & instructions that must be followed to
produce the best results.

• Results means the outcome or the completed computer-


assisted answer.

• Program means the set of instructions that make up the


solution after they have been coded into a particular
computer language.

Module 1 Session 1 25
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

DIFFICULTIES
Outline WITH
OutlinePROBLEM SOLVING

• Lack of problem solving experience


• Inadequate solution steps
• Incorrect problem definition
• Alternatives chosen incorrectly
• Invalid logic
• Incorrect solution evaluation

Module 1 Session 1 26
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Outline

PROGRAMMING PHASE

Problem Solving Phase


Algorithm, Flowchart, Pseudocode

Implementation Phase
Programming language

Module 1 Session 1 27
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Outline

ALGORITHM

Module 1 Session 1 28
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline What isOutline


an Algorithm

Module 1 Session 1 29
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Outline

Module 1 Session 1 30
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline ALGORITHM
Outline

• A sequential solution of any program that written in


human language, called algorithm.

• Algorithm is first step of the solution process, after


the analysis of problem, programmer write the
algorithm of that problem.

• Any problem solution can be expressed in a list of


executable instructions

Module 1 Session 1 31
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Outline

Module 1 Session 1 32
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

• An algorithm is definedOutline
Outline as a step-by-step procedure or
method for solving a problem by a computer in a finite
number of steps.

Module 1 Session 1 33
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Let’s
Outline try

• The taxi algorithm

• The call-me algorithm

Module 1 Session 1 34
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Outline
The taxi algorithm
• Go to the taxi stand.
• Get in a taxi.
• Give the driver- address

The call-me algorithm:


• When your plane arrives, call my cell phone.
• Meet me outside baggage claim.

Module 1 Session 1 35
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Characteristics
Outline Outline of Algorithm

• Each and every instruction should be precise and


unambiguous.
• The instructions should not be repeated infinitely.
• Ensure that the algorithm will ultimately terminate.
• Should be written in sequence.
• Must be written in normal English.
• The desired result should be obtained only after the algorithm
terminates.

Module 1 Session 1 36
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Factors
Outline AffectingOutline
Quality of Algorithm

• Time – the better algorithm takes lesser time to compute.

• Memory- the better algorithm take lesser memory to access.

• Accuracy- multiple algorithm gives correct solution but only


some algorithms give actual output.

• Sequence- procedure of an algorithm must form in a


sequence

Module 1 Session 1 37
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline
Formal Way
Outline

• Every algorithm should have the following 5 characteristic


feature:

1. Input

2. Output

3. Definiteness

4. Effectiveness

5. Termination

Module 1 Session 1 38
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Algorithm:
Outline Calling a friend on the telephone
Outline
Input: The telephone number of your friend.
Output: None
Steps:
1. Pick up the phone and listen for a dial tone
2. Press each digit of the phone number on the phone
3. If busy, hang up phone, wait 5 minutes, jump to step 2
4. If no one answers, leave a message then hang up
5. If no answering machine, hang up and wait 2 hours, then
jump to step 2
6. Talk to friend
7. Hang up phone

Module 1 Session 1 39
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Algorithm
Outline to findOutline
out number is odd or
even
Step 1 : start
step 2 : input number
step 3 : rem=number mod 2
step 4 : if rem=0 then
print "number even"
else
print "number odd"
endif
step 5 : stop

Module 1 Session 1 40
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Problems
Outline

1. Addition of two numbers


2. Given a list of positive numbers, return the largest number on the
list.
3. To find the largest among three different numbers entered by
user.
4. Determine a students final grade and indicate whether it is pass or
fail. The final grade is calculated as the average of four marks
5. To Find Factorial of a given number

Module 1 Session 1 41
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline ADVANTAGES
Outline

 Step-by-step process of a solution to a given problem ,which


is very easy to understand
 It has got a definite procedure.
 It easy to first develop an algorithm, then convert it into a
flowchart &then into a computer program.
 It is independent of programming language.
 It is easy to debug as every step is got its own logical
sequence.

Module 1 Session 1 42
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline DISADVANTAGE
Outline

• It is time consuming & cumbersome as an algorithm is developed


first which is converted into flowchart &then into a computer
program.

Module 1 Session 1 43
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Outline

Module 1 Session 1 44
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline POINTS Outline


TO PONDER
• An algorithm is defined as a step-by-step procedure or method
for solving a problem by a computer in a finite number of steps.
• Characteristics of Algorithm
• Factors- Time, memory, accuracy, sequence.

Module 1 Session 1 45
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline KeyOutline
Terms
• Problem solving

• Algorithmic solutions

• Heuristic Solutions

• Programming Phase

• Factors

Module 1 Session 1 46
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Outline

• Stages of Algorithm

• Why We need to check Pre & Post Condition of an algorithm

• What the factors affect quality of algorithm

• Whether Algorithm can be ambiguous.

Module 1 Session 1 47
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Outline

• At the end of this session , students


Learning should able to understand the
Outcome fundamentals of Algorithm.

Module 1 Session 1 48
18CS101 – C PROGRAMMING FOR PROBLEM SOLVING

Outline Outline

Module 1 Session 1 49

You might also like