Unit i Full Notes_pspc_ppt Slides (1)
Unit i Full Notes_pspc_ppt Slides (1)
UNIT NO 1
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C
(common to All Branches)
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
WHAT IS A MODEL?
❖ An abstract description of a real world entity
❖ Attempts to capture the essential features while suppressing the less important details.
❖ Important to have a model that is both precise and as simple as possible to support theoretical
There are many models of computation but we shall state only a few here as follows:
❖ Random Access Machines
❖ Turing Machines
❖ Pointer Machines
❖ Decision Trees
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
A straight-line program is set of steps each of which is an input step, denoted (s READ x),
an output step, denoted (s OUTPUT i), or a computation step, denoted (s OP i . . . k).
Here s is the number of a step, x denotes an input variable, and the keywords READ, OUTPUT,
and OP identify steps in which an input is read, an output produced, and the operation OP is
performed.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
TURING MACHINES:
A mathematical model which consists of an infinite length tape
divided into cells on which input is given.
It consists of a head which reads the input tape.
A state register stores the state of the Turing machine.
After reading an input symbol, it is replaced with another symbol,
its internal state is changed, and it moves from one cell to the
right or left.
If the TM reaches the final state, the input string is accepted,
otherwise rejected.
POINTER MACHINE:
A model of computation whose memory consists of an unbounded collection of registers, or records,
connected by pointers.
Each register may contain an arbitrary amount of additional information. No arithmetic is allowed to
compute the address of a register. The only way to access a register is by following pointers.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
DECISION TREES:
A decision tree is a decision support tool that uses a tree-like model of decisions and their
possible consequences, including chance event outcomes, resource costs, and utility.
It is one way to display an algorithm that only contains conditional control statements.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Procedural Programming can be defined as a programming model which is derived from structured
programming, based upon the concept of calling procedure.
Object oriented programming can be defined as a programming model which is based upon the
concept of objects.
In object oriented programming, computer programs are designed using the concept of objects that
interact with real world.
In object oriented programming, program is divided into small parts called objects.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Parallel processing is technique which enables the system to achieve simultaneous data-processing
tasks to increase the computational speed.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Logic programming languages, of which PROLOG (programming in logic) is the best known, state a
program as a set of logical relations (e.g., a grandparent is the parent of a parent of someone).
Such languages are similar to the SQL database language. ( a query by searching and answer a query.)
PROLOG has been used extensively in natural language processing and other AI programs
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Functional programming paradigms – The functional programming paradigms has its roots in
mathematics and it is language independent. The key principal of this paradigms is the execution of
series of mathematical functions. The central model for the abstraction is the function which are meant
for some specific computation and not the data structure. The function hide their implementation.
Function can be replaced with their values without changing the meaning of the program.
Data driven programming is a programming model where the data itself controls the flow of the
program and not the program logic.
It is a model where you control the flow by offering different data sets to the program where the
program logic is some generic form of flow or of state-changes.
Thank you
SUBJECT CODE
UNIT NO 1
INTRODUCTION TO PROGRAMMING AND
ALGORITHMS FOR PROBLEM SOLVING
I I
ESCS101
Problem Solving and Programming in C
(Common to ALL Departments)
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
The program development life cycle is a set of steps or phases that are used to develop a program in
any programming language.
The program development life cycle is a detailed plan describing how to develop, maintain, replace
and alter or enhance specific program/software.
The life cycle defines a methodology for improving the quality of program/software and the overall
development process.
Program Development Life Cycle (PDLC) is a systematic way of developing quality program/software.
It provides an organized plan for breaking down the task of program development into manageable
chunks, each of which must be successfully completed before moving on to the next phase.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
1. Problem Definition
2. Problem Analysis
3. Algorithm Development
4. Coding & Documentation
5. Testing & Debugging
6. Maintenance
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
2. Problem Analysis
In phase 2, we determine the requirements like variables, functions, etc. to solve the problem.
That means we gather the required resources to solve the problem defined in the problem
definition phase. We also determine the bounds of the solution.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
The pseudocodes, flowcharts and decision tables are documentation for users.
It is a manual that provides an overview of the program’s functionality, features,
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
6. Maintenance
During this phase, the program is actively used by the users. If any enhancements found in
this phase, all the phases are to be repeated to make the enhancements. That means in this
phase, the solution (program) is used by the end-user. If the user encounters any problem or
wants any enhancement, then we need to repeat all the phases from the starting, so that the
encountered problem is solved or enhancement is added.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Video Link
UNIT NO. 1
1.3 ALGORITHMS
I I
2020ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C
(Common to CSE & IT)
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
ALGORITHMS
ALGORITHMS
Advantages of Algorithms:
1. It is easy to understand.
2. Algorithm is a step-wise representation of a solution to a given problem.
3. In Algorithm the problem is broken down into smaller pieces or steps
hence, it is easier for the programmer to convert it into an actual program.
Disadvantages of Algorithms:
Step 1 − START
Step 6 − print c
Step 7 − STOP
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
step1:start
step7:stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Step-1 Start
Step-2 Input Side Length of Square say L
Step-3 AREA = L x L
Step-4 PERIMETER = 4 x L
Step-5 Display AREA, PERIMETER
Step-6 Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Step 1: Start
Step 2: Declare variables first_term as f1 ,second_term as f2 and temp.
Step 3: Initialize variables f1 ← 0 and f2 ← 1
Step 4: Display f1 and f2
Step 5: Repeat the steps if f2 ≤ 1000
5.1: temp ← f2
5.2: f2 ← f2 + f1
5.3: f1 ← temp
5.4: Display f2
Step 6: Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Step 1: Start
Step 2: Read year y.
Step 3: If y mod 400 equal to 0 or y mod 100 not equal to 0 and y mod 4
equal to 0 goto step 4 else goto step 5
Step 4: Print y is leap year
Step 5: Print y is not leap year
Step 6: Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Thank You
SUBJECT CODE
UNIT NO 1
INTRODUCTION TO PROGRAMMING AND
ALGORITHMS FOR PROBLEM SOLVING
I I
ESCS101
Problem Solving and Programming in C
(Common to ALL Departments)
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Pseudocode
❖ ’Pseudo’ means imitation and ‘code’ refer to instruction written in the programming
language.
❖ Pseudo code is not a real programming language. It is the generic way of describing an
algorithm without using any specific programming language-related notations.
❖ Purpose- to define the procedural logic of an algorithm in a simple, easy-to- understand
for its readers.
❖ Consists of natural language-like statements that precisely describe the steps of an
algorithm or program.
❖ Pseudo code cannot be compiled , executed and there are no real formatting or
syntax rules for writing pseudo codes.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Features of Pseudocode
Example:
IF(condition) THEN
List of Actions
ELSE
List of different Actions
END IF
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
BEGIN
NUMBER a, b, C
READ a,b
COMPUTE C=a*b DETERMINE C= a*b
PRINT C
END
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Approach 1:
Approach 2:
BEGIN
BEGIN
NUMBER a,b,c
NUMBER a,b,c
READ a,b,c
READ a,b,c
IF (a>b) and (a>c) THEN
IF (a>b) and (a>c) THEN
WRITE a is big
WRITE a is big
ENDIF
ELSE IF (b>c) THEN
IF (b>c) and (b>c)THEN
WRITE b is big
WRITE b is big
ELSE
ELSE
WRITE c is big
WRITE c is big
END IF
END IF
END
END
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
BEGIN
INITIALIZE X to one
WHILE (X <=n)
END WHILE
PRINT SUM
END
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
BEGIN
NUMBER b1,b2,area,perimeter
INPUT b1
INPUT b2
COMPUTE area=b1*b2
CALCULATE perimeter=2*(b1+b2)
OUTPUT area
OUTPUT perimeter
END
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
BEGIN
NUMBER counter
OUTPUT counter
ENDFOR
END
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
BEGIN
NUMBER num1,num2
WRITE “Please enter two numbers to add”
READ num1
READ num2
COMPUTE Sum = num1+num2
COMPUTE Avg = Sum/2
WRITE Sum, Avg
END
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
UNIT NO 1
INTRODUCTION TO PROGRAMMING AND
ALGORITHMS FOR PROBLEM SOLVING
1.5 Flowchart
I I
20ESCS101
Problem Solving and Programming in C
(Common to ALL Departments)
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
● Flowcharts use simple geometric shapes to depict processes and arrows to show relationships and
process/data flow.
● A graphical tool that diagrammatically depicts the steps and structure of an algorithm or program is
called as flowchart.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
Flow Chart:
● When designing a flowchart, each step in the process is depicted by a different symbol and is
associated with a short description.
● The symbols in the flowchart are linked together with arrows to show the flow of logic in the
process.
Basic symbols:
Start and end symbols are also known as the terminal symbols
and are represented as circles, ovals, or rounded rectangles. Terminal
Start Stop symbols are always the first and the last symbols in a flowchart.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
Input/ Output Input/output symbols are represented using a parallelogram and are
used to get inputs from the users or display the results to them.
FLOWCHART
● The two arrows coming out of it, one from the bottom vertex and the
other from the right vertex, correspond to Yes or True, and No or False,
T respectively.
Arrows depict the flow of control of the program. They illustrate the
exact sequence in which the instructions are executed.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
Control structure in flow chart:
• Selection(branch) Structure – it asks a true/ false question and then selects the
next instructions based on the answer Eg: if condition
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
• Loop (Iterative)structure – It repeats the execution of a block of instructions until the condition satisfies
FLOWCHART
Flowchart Advantages
• Using only very few symbol, complex problem can be represented in flowchart.
FLOWCHART
Flowchart Disadvantages
FLOWCHART
if( condition)
block 1
else
block2
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
Control structure : Selection
Multiway selection
switch(exp)
{
case 1: body
case 2:body
.
.
default:body
}
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
for(initialization;test-exp;inc/dec)
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
Control structure : Looping Flowchart
while loop
while(test-exp)
{
body
}
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
do
{
body
}while(test-exp);
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
Examples: Adding two numbers
start
Read num1,
num2
result= num1+num2
Store result
stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
Average of 3 numbers
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
Converting fahrenheit to celsius
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
To calculate simple interest
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Start
To find greatest of two number
Read a,b
stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART Start
Example: Flow chart for finding
greatest of three numbers
Declare a,b,c
Read a,b,c
If a>b
and true Print a is big
a>c
?
false
If b>c
and true
Print b is big
b>a
?
false
FLOWCHART
FLOWCHART
Finding leap year or not
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART Start
To find factorial of a given number
Declare n,i and
factorial
Read n
factorial=1
i=1
If
i<=n
?
true false
factorial = factorial*i
i = i+1
Print factorial
Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART Start
To find factorial of a given number
Declare n and factorial
Read n
factorial=1
If n>0
?
true false
factorial = factorial * n
n = n-1
Print factorial
Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART Start
Draw flow chart generate Fibonacci series till term≤1000
0 1 1 2 3 5 8 13 ……….
Declare f1,f2,temp
f1=0
f2=1
Display f1 and f2
If
f2 <
1000
?
true false
temp = f2
f2 = f2 + f1
f1 = temp
Print f2
Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
Adding integers from 1 to N
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
A simple calculator program
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
To calculate area of a sphere
Yes
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Video Link
https://youtu.be/nG_2fCIjK8U
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Video Link
https://youtu.be/nG_2fCIjK8U
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
THANK YOU
SUBJECT CODE
UNIT NO. 1
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C
(Common to CSE & IT)
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
PROGRAMMING LANGUAGES
PROGRAMMING LANGUAGES
●Programming environment
●Syntax of the instructions/ Operations
●Set of recognizable characters
●Variables
●Constants
●Keywords
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
● Operators
● Arrays
● Strings
● File handling
● Error and exception handling
● Built in and user defined functions
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
● A programming language must be simple, easy to learn and use, have good
readability and be human recognizable.
● Abstraction is a must-have Characteristics for a programming language in
which the ability to define the complex structure and then its degree of
usability comes.
● A portable programming language is always preferred.
● Programming language’s efficiency must be high so that it can be easily
converted into machine code and executed consumes little space in
memory.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Programming Constructs
Any good programming language should have constructs for supporting the following
three ways of instruction execution, namely:
1.Sequence
2.Selection
3.Iteration
●Sequence is rather easy to implement where the instructions are executed one after the
other without any change in the order of execution and it’s order of arrangement.
●Selection is the mechanism by which only one course of instruction is selected and
executed, from among more than one set of instructions available. These instructions are
selected based on the outcome of a condition that evaluates to True or False.
Sometimes, there may be more than one choice available. Based on the choice of the
user, the programming construct may select one of the available options and execute the
same.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Programming Constructs
Compilation
The compilation is a process of converting the source code into object code.
A software (another program) would convert the program into machine understandable
format. This program is called as a compiler.
The compiler reads through the program one or more times (called as Phases of a
compiler) and then converts it into an object file.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Compilation
A translation program that converts the high level language constructs into machine
readable format can be an Assembler, interpreter or compiler.
The difference between compiler and interpreter is that an interpreter reads the high level
language program line by line whereas the compiler reads the program in entirety and
then converts it into machine language
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Steps in Compilation
The compilation process in C language is made up of four steps
1.Preprocessing. A preprocessor is a text substitution tool or macro preprocessor for C,
that provides the ability for the inclusion of header files, macro expansions, conditional
compilation, and line control.
The # symbol marks the statements that are to be processed by the preprocessor.
1.The second stage is the compilation, where the preprocessed code is translated to
assembly instructions specific to the target processor architecture.
2.The third stage is the assembling of the instructions into machine readable format or
object code .
3.The last stage is linking of the missing pieces of the code to get a complete executable
program.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Linking:
It is the process of combining separate pieces of code together to form a single
executable program.
The use of linkers allows a single monolithic program to be split into various modules and
developed separately.
These modules help in developing reusable components, error free code, Modular
programming, workload management and also timely completion of very large projects.
Individual modules built by various programmers are individually compiled and then put
together by a linker.
Types of linking:
There are two types of linking, namely static and dynamic linking.
In static linking, all the modules that need to be put together are decided first, then
compiled and then are linked together to form a single object file. The addresses
are refined and external variables are resolved. This is called a static linking.
In dynamic linking, the number of modules to be linked together is not decided
beforehand. The modules are decided during the runtime or execution of the
program. The choice of the modules may depend on the outcome of some
conditional expressions or choice of the user or errors / exceptions that may result
during the course of the program. The modules to be linked with the program are
selected at runtime and the instruction and the variable address resolution happen
at runtime. This is the most efficient way of managing the memory and also to keep
the size of the program a minimum.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Types of Linkers:
● Linkage Editor: It is a linker that generates the relocatable, executable module.
● Dynamic Linker: It defers/postpones the linkage of some external modules until
the load module/executable module is generated. Here, linking is done during
load time or run time.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Loading a Program:
● Once the program is compiled and linked, it is to be loaded into memory for
execution by the operating system. There are different types of loaders.
● Absolute loader: One in which the program is always loaded into the same address
● Relocatable loader: A loader which can relocate the program depending on the
availability of the memory
● Dynamic Run time loader: A loader which would load the module only when it is
called in and not before that.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Testing is the process of verifying and validating that a software or application is bug free,
meets the technical requirements , the user requirements effectively and efficiently with
handling all the exceptional and boundary cases.
Debugging is the process of fixing the errors found during the testing process.
1 Definition Testing is a process to check if the application Debugging is the activity performed
is working the same as it was supposed to do, by developers to fix the bug found in
and not working as it was not supposed to do. the system.
2 Objective To find bugs and errors in an application which To find the exact root cause at code
get missed during the unit testing by the level to fix the errors and bugs found
developer. during the testing.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
3 Perform As Testing is mainly to find out the errors and bugs is While on other hand Debugging is to find
mainly performed by the testers. Also if testing is at the missing or de-faulty code in an
developer end known as unit testing then it is application hence major performance by
performed by the Developer. the developers only.
4 Knowledge As Testing covers the functional and behavioral flow To find the error at code level so technical
Required of an application so only functional knowledge is and code level knowledge is required for
required for the tester to perform the testing. the developer to perform debugging.
5 Automation Testing can be manual or made automated with the Debugging can't be automated, it is
help of different tools. always manual.
6 Level Testing on the basis of level of performance is at a No such level of Debugging is possible
different level i.e., unit testing, integration testing,
system testing, etc.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Documentation
Any written text, illustrations or video that describe a software or program to its users is
called program or software document.
Documentation describes the code and its functionality.
It may also have information about the date of development, the development team,
usage, system requirements and pitfalls of the system.
At various stages of development multiple documents may be created for different users.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Documentation
Types of documentation,
• User manual − instructions and procedures for end users
• Operational manual − It lists and describes all the operations
• Design Document − describes design elements in detail. details like data flow
diagrams, entity relationship diagrams, etc.
• Requirements Document − It has a list of all the requirements of the system.
• Technical Documentation − algorithms, flowcharts, program codes, functional
modules, etc.
• Testing Document − It records test plan, test cases, validation plan, verification plan,
test results
• List of Known Bugs − Every software has bugs or errors that cannot be removed
because either they were discovered very late or are harmless or will take more effort
and time than necessary to rectify. These bugs are listed with program documentation
so that they may be removed at a later date.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Documentation
System documentation has information about the various components of the system
They are requirement documents, design decisions, architecture descriptions, program
source code, and FAQs.
Process documentation involves description about the tasks carried out in the system, for
example standards, project documentation, such as project plans, test schedules,
reports, meeting notes, or even business correspondence.
User document will help the users understand the various ways in which he or she can
interact with the system, the various menus and reports available in the system and how
to exploit them.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Video Links
Compilation stages
https://youtu.be/cJDRShqtTbk
Software Testing
https://www.youtube.com/watch?v=GOVEJTzwzFE
Types of Programming Language
https://www.youtube.com/watch?v=aYjGXzktatA
Programming Constructs
https://www.youtube.com/watch?v=eSYeHlwDCNA
SUBJECT CODE
UNIT NO 1
INTRODUCTION TO PROGRAMMING AND
ALGORITHMS FOR PROBLEM SOLVING
ESCS101
Problem Solving and Programming in C
(Common to ALL Departments)
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
CONTROL STRUCTURES
2. Selection structures are used to perform ‘decision making‘ and then branch the program flow
based on the outcome of decision making. It is also called as Decision Structures. Selection structures are
implemented with If, If Else and Switch statements. If and If Else statements are 2 way branching statements
where as Switch is a multi branching statement.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
3. Loop structure is used to execute a certain set of actions for a predefined number of times or
until a particular condition is satisfied. It is also called as repetition or iteration structures. There are 3 control
statements available to implement loop structure. They are While, Do while and For statements.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
3. Loop structure is used to execute a certain set of actions for a predefined number of times or
until a particular condition is satisfied. It is also called as repetition or iteration structures. There are 3 control
statements available to implement loop structure. They are While, Do while and For statements.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Algorithmic problem solving is solving problem that require the formulation of an algorithm for the
solution.
Understanding the Problem
❖ It is the process of finding the input of the problem that the algorithm solves.
❖ It is very important to specify exactly the set of inputs the algorithm needs to handle.
❖ A correct algorithm is not one that works most of the time, but one that works correctly for all
legitimate inputs.
Ascertaining the Capabilities of the Computational Device
❖ If the instructions are executed one after another, it is called sequential algorithm.
❖ If the instructions are executed concurrently, it is called parallel algorithm.
Choosing between Exact and Approximate Problem Solving
❖ The next principal decision is to choose between solving the problem exactly or solving it
approximately.
❖ Based on this, the algorithms are classified as exact algorithm and approximation algorithm.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Pseudocode is usually more precise than natural language, and its usage often yields more
❖ In the earlier days of computing, the dominant vehicle for specifying algorithms was a flowchart,
❖ Programming language can be fed into an electronic computer directly. Instead, it needs to be
converted into a computer program written in a particular computer language. We can look at
such a program as yet another way of specifying the algorithm, although it is preferable to
2. simplicity.
❖ An algorithm should be precisely defined and investigated with mathematical expressions.
❖ Simpler algorithms are easier to understand and easier to program.
❖ Simple algorithms usually contain fewer bugs.
Coding an Algorithm
❖ Programming the algorithm by using some programming language.
❖ Formal verification is done for small programs. Validity is done thru testing and debugging.
❖ Most algorithms are destined to be ultimately implemented as computer programs.
Programming an algorithm presents both a peril and an opportunity.
❖ A working program provides an additional opportunity in allowing an empirical analysis of the
underlying algorithm. Such an analysis is based on timing the program on several inputs and
then analysing the results obtained.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
❖ In a sequence structure, an action, or event, leads to the next ordered action in a predetermined order.
❖ The sequence can contain any number of actions, but no actions can be skipped in the sequence.
❖ The program, when run, must perform each action in order with no possibility of skipping an action or
Advantage: There is no separate control statements are needed in order to execute the statements
Disadvantage is that there is no way to change the sequence. The solution for this is branching.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Step 1: Start
Step 4: Display A
Step 5: Stop
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Step 1: Start
Step 6: Stop
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Step 1: Start
Step 4: Display S
Step 5: Stop
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Step 1: Start.
Step 2: Read F.
Step 3: C=(5(F-32))/9.
Step 4: Print C.
Step 5: Stop.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Step 1: Start
Step 5: Stop
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Step 1 : Start
Start 7 : Stop
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Step 1 : Start
Start 7 : Stop
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
VIDEO LINK
1. https://www.youtube.com/watch?v=deb5ztpTjYY
1. https://www.youtube.com/watch?v=EcPY7Mg8bjo
1. https://www.youtube.com/watch?v=OoShU65HemA
SUBJECT CODE
UNIT NO 1
INTRODUCTION TO PROGRAMMING AND
ALGORITHMS FOR PROBLEM SOLVING
ESCS101
Problem Solving and Programming in C
(Common to ALL Departments)
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
❖ A selection / Decision making statement causes the program control to be transferred to a specific part
of the program based upon the condition.
❖ If the conditional test is true, one part of the program will be executed, otherwise it will execute the other
part of the program.
❖ Decision Making and Branching can be said as Selection/ Conditional /Branching
statements/structures.
❖ They decide the flow of the statements which is based on the evaluation condition.
❖ Decision making is anticipation of conditions occurring while execution of the program and specifying
actions taken according to the conditions.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Decision structures evaluate multiple expressions which produce TRUE or FALSE as outcome. We need to
determine which action to take and which statements to execute if outcome is TRUE or FALSE otherwise.
IF condition THEN
sequence 1
Example
IF THEN ELSE
IF age>= 18 THEN
DISPLAY message “Eligible to vote”
ELSE
DISPLAY message “Not eligible to vote”
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
IF(condition 1) THEN
IF (condition 2) THEN
body of if
ELSE
Body of else
ELSE
Body of else
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Flowchart:
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
UNIT NO 1
INTRODUCTION TO PROGRAMMING AND
ALGORITHMS FOR PROBLEM SOLVING
ESCS101
Problem Solving and Programming in C
(Common to ALL Departments)
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
❖Iteration is the repetition part of an algorithm/program until a condition is met or might repeat for a
specified number of times.
❖The repetition structure is the construction of statement in such a way where statements can be
executed repeatedly until a condition evaluates to true or false.
❖Iteration is also known as looping.
❖For example, a very simple algorithm for eating breakfast cereal might consist of these steps:
1. Put cereal on bowl
2. Add milk to cereal
3. Use spoon to eat cereal and milk
4. Repeat step 3 until all cereal and milk in the bowl is eaten.
5. Rinse the bowl and spoon.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
process(es)
ENDWHILE
❖ It executes the body of the loop before testing the termination condition.
❖ This construct is often referred to as an unguarded loop.
❖ The body of the loop is repeatedly executed until the termination condition is true.
❖ In pseudocode, post-test is expressed as:
REPEAT
process
❖ The statements of a post-test loop are executed at least once even if the condition is originally true
❖ The body of the pre-test loop may never be executed if the termination condition is originally true.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Syntax
statement(s);
}
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
❖ The init step is executed first, and only once. This step allows you to declare and initialize any loop
control variables. You are not required to put a statement here, as long as a semicolon appears.
❖ Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false, the body of
the loop does not execute and the flow of control jumps to the next statement just after the 'for' loop.
❖ After the body of the 'for' loop executes, the flow of control jumps back up to the increment statement.
This statement allows you to update any loop control variables. This statement can be left blank, as
long as a semicolon appears after the condition.
❖ The condition is now evaluated again. If it is true, the loop executes and the process repeats itself
(body of loop, then increment step, and then again condition). After the condition becomes false, the
'for' loop terminates.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Flow diagram:
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Algorithm: Flowchart:
Step 1: Start.
Step 2: Read n
otherwise go to step 7.
Step 5: f = f * n
Step 8: Stop.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
2. while Loop:
❖ A while loop repeatedly executes a target statement as long as a given condition is true.
Syntax
❖ The syntax of a while loop is −
while ( condition)
statement(s);
Flow diagram:
Algorithm: Flowchart:
Start
Step 1: Start.
Step 8: Stop
Print f
Stop
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Syntax
❖ The syntax of a do...while loop is −
do
statement(s);
} while ( condition );
❖ Notice that the conditional expression appears at the end of the loop, so the statement(s) in the loop
executes once before the condition is tested.If the condition is true, the flow of control jumps back up to do,
and the statement(s) in the loop executes again. This process repeats until the given condition becomes
false.
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Flow diagram:
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Algorithm: Flowchart:
Start
Step 1: Start.
Stop
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Nested Loops:
Syntax
The syntax for a nested for loop statement The syntax for a nested while loop statement is
as follows − as follows −
statement(s); statement(s);
} }
statement(s); statement(s);
} }
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
do {
statement(s);
do {
statement(s);
}while( condition );
}while( condition );
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
INITIALIZE I to zero
DO WHILE (I <100)
INCREMENT I
END DO WHILE
PRINT SUM
STOP
ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
WRITE F1,F2
F=F1+F2
READ N
WHILE (F<N)
F=F1+F2
F1=F2
F2=F
WRITE F
END WHILE