Professional Documents
Culture Documents
20ESCS101
CODE
UNIT NO 1
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C
(common to All Branches)
20ESCS101
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
studies of the entity modelled.
WHAT DOES COMPUTATION MEAN?
❖ A computation is any type of calculation that includes both arithmetical and non-arithmetical
steps and which follows a well-defined model (e.g. an algorithm).
❖ Mechanical or electronic devices (or, historically, people) that perform computations are
known as computers.
❖ An especially well-known discipline of the study of computation is computer science.
THEN WHAT IS MODEL OF COMPUTATION ?
❖ Describes a class of computers and allows algorithms to be written for a general model
rather than for a specific computer.
20ESCS101
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
❖ 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.
20ESCS101
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.
20ESCS101
PROGRAMMING PARADIGMS:
❖Paradigm can also be termed as method to solve some problem or do some task.
❖Programming paradigm is an approach to solve problem using some programming language or
also we can say it is a method to solve a problem using tools and techniques that are available to
us following some approach.
❖There are lots for programming language that are known but all of them need to follow some
strategy when they are implemented and this methodology/strategy is paradigms.
20ESCS101
https://www.youtube.com/watc
h?v=vJqBBh2XFTM
https://www.youtube.com/w
atch?v=Zc54gFhdpLA
https://forms.gl
e/v3wzWpXvw
https://www.youtube.com/wa U8hqJJ68
tch?v=4mjhQahK3GU
20ESCS101
Thank you
SUBJECT CODE
UNIT NO 1
INTRODUCTION TO PROGRAMMING AND
ALGORITHMS FOR PROBLEM SOLVING
I I
20ESCS101
Problem Solving and Programming in C
(Common to ALL Departments)
20ESCS101
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
20ESCS101
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.
20ESCS101
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.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Video Link
UNIT NO. 1
1.3 ALGORITHMS
I I
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C
(Common to CSE & IT)
20PCSPC101
ADVANCED DATA STRUCTURES AND ALGORITHMS
ALGORITHMS
Step 1 − START
Step 6 − print c
Step 7 − STOP
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Step-1 Start
Step-3 F = (9.0/5.0 x C) + 32
Step-5 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 a,b
Step 3: Read variables a,b
Step 4: If a > b
Display a is the largest number.
Else
Display b is the largest number.
Step 5: Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Step 1: Start
Step 2: Declare variables a, b, c, D, x1, x2, rp and ip;
Step 3: Calculate discriminant
D ← b2-4ac
Step 4: If D ≥ 0
r1 ← (-b+√D)/2a
r2 ← (-b-√D)/2a
Display r1 and r2 as roots.
Else
Calculate real part and imaginary part
rp ← -b/2a
ip ← √(-D)/2a
Display rp+j(ip) and rp-j(ip) as roots
Step 5: Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Step 1: Start
Step 2: Declare variables n, factorial and i.
Step 3: Initialize variables
factorial ← 1
i←1
Step 4: Read value of n
Step 5: Repeat the steps until i = n
5.1: factorial ← factorial*i
5.2: i ← i+1
Step 6: Display factorial
Step 7: Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Step 1: Start
Step 2: Declare variables first_term,second_term and temp.
Step 3: Initialize variables first_term ← 0 second_term ← 1
Step 4: Display first_term and second_term
Step 5: Repeat the steps until second_term ≤ 1000
5.1: temp ← second_term
5.2: second_term ← second_term + first_term
5.3: first_term ← temp
5.4: Display second_term
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
20ESCS101
Problem Solving and Programming in C
(Common to ALL Departments)
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Pseudocode
Features of Pseudocode
Example:
IF(condition) THEN
List of Actions
ELSE
List of different Actions
END IF
Example: pseudo code for Multiplying two numbers
READ a,b
COMPUTE C=a*b
PRINT C
STOP
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
BEGIN
READ a,b,c
WRITE a is big
WRITE b is big
ELSE
WRITE c is big
END IF
END
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
BEGIN
INITIALIZE I to zero
DO WHILE (I <100)
INCREMENT I
END DO WHILE
PRINT SUM
STOP
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
BEGIN
NUMBER b1,b2,area,perimeter
INPUT b1
UNPUT b2
area=b1*b2
perimeter=2*(b1+b2)
OUTPUT area
OUTPUT perimeter
END
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
BEGIN
NUMBER counter
OUTPUT counter
ENDFOR
END
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
BEGIN
WRITE “Please enter two numbers to add”
READ num1
READ num2
COMPUTE Sum = num1+num2
COMPUTE Avg = Sum/2
WRITE Sum, Avg
END
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
VIDEO LINK
1. https://www.youtube.com/watch?v=preyTbKXDoQ
2. https://www.youtube.com/watch?v=6fHRtZC_kXU
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
THANK YOU
SUBJECT CODE
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
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
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
for(initialization;test-exp;inc/dec)
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
Flowchart of 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
switch Statement Flowchart
switch(exp)
{
case 1: body
case 2:body
.
.
default:body
}
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
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 )
FLOWCHART
Finding leap year or not
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
To check armstrong no or not
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
FLOWCHART
To find factorial of a given number
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 )
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 )
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
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C
(Common to CSE & IT)
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
PROGRAMMING LANGUAGES
●Programming environment
●Syntax of the instructions/ Operations
●Set of recognizable characters
●Variables
●Constants
●Keywords
20ESCS101
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
20ESCS101
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.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Programming Constructs
Compilation
The programming language is easier to be understood by the user, but it cannot be
executed by the computer in the present form. It needs to be presented in the form that
could be understood by the machine. 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.
A translation program that converts the high level language constructs into machine
readable format can be an Assembler, interpreter or compiler.
Assembler is used for converting mnemonics into machine language whereas an
interpreter and a compiler is used for converting high level languages into machine
language.
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
20ESCS101
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.
2.The second stage is the compilation, where the preprocessed code is translated to
assembly instructions specific to the target processor architecture. These form an
intermediate human readable language.
3.The third stage is the assembling of the instructions into machine readable format or
object code .
4.The last stage is linking of the missing pieces of the code to get a complete executable
program.
20ESCS101
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.
20ESCS101
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.
20ESCS101
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.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
2 Objective Main objective of Testing is to find bugs and errors in an On other hand the main
application which get missed during the unit testing by objective of Debugging is
Testing Debugging the developer. to find the exact root
Process of verifying whether software meets the requirements and is free of defects or bugs.
Process of identifying, analyzing, and fixing defects or bugs in software after they have been found. cause at code level to fix
Aimed at preventing and catching errors early in the software development life cycle. Aimed at removing errors
after they have been found, often after the software has been released. the errors and bugs found
Typically performed by a dedicated team of testers who use a variety of techniques and tools to test the software.
Typically performed by developers who use specialized tools and techniques to analyze and fix bugs. 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 behavioural flow On other hand Debugging is to find the
Required of an application so only functional knowledge is error at code level so technical and code
required for the tester to perform the testing. level knowledge is required for the
developer to perform debugging.
5 Automation Testing can be manual or made automated with the On other hand Debugging can't be
help of different tools. automated, it is always manual.
6 Level Testing on the basis of level of performance is at a On other hand no such level of Debugging
different level i.e., unit testing, integration testing, is possible
system testing, etc.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Documentation
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.
There are two types of documentation, namely system documentation and User Documentation.
System documentation has information about the various components of the system, like
requirements 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.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
References- Courtesy:
1.https://www.tutorialspoint.com/computer_programming/computer_progr
amming_basics.htm
2.https://www.geeksforgeeks.org/introduction-to-programming-languages/
3.https://www.britannica.com/technology/computer-programming-language
4.https://techdifferences.com/difference-between-linker-and-loader.html
5. https://dzone.com/articles/the-differences-between-testing-and-debugging
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)
Video Links
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
Phases of compiler
https://www.youtube.com/watch?v=0jvKnJK0bnA
SUBJECT CODE
UNIT NO 1
INTRODUCTION TO PROGRAMMING AND
ALGORITHMS FOR PROBLEM SOLVING
20ESCS101
Problem Solving and Programming in C
(Common to ALL Departments)
20ESCS101
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.
20ESCS101
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.
20ESCS101
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.
20ESCS101
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.
20ESCS101
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
❖ 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.
20ESCS101
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.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Step 1: Start
Step 4: Display A
Step 5: Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Step 1: Start
Step 6: Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Step 1: Start
Step 4: Display S
Step 5: Stop
20ESCS101
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.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Step 1: Start
Step 5: Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Step 1 : Start
Start 7 : Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Step 1 : Start
Start 7 : Stop
20ESCS101
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
20ESCS101
Problem Solving and Programming in C
(Common to ALL Departments)
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Decision structures evaluate multiple expressions which produce TRUE or FALSE as outcome.
You 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”
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
• As the flowchart version of the multi-way selection indicates, only one process on each pass is executed as
a result of the implementation of the multi-way selection.
20ESCS101
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
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
UNIT NO 1
INTRODUCTION TO PROGRAMMING AND
ALGORITHMS FOR PROBLEM SOLVING
20ESCS101
Problem Solving and Programming in C
(Common to ALL Departments)
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
❖Iteration is the repetition part of an algorithm 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.
20ESCS101
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
❖ An important difference between a pre-test and post-test loop is that the statements of a post-test
loop are executed at least once even if the condition is originally true, whereas the body of the pre-
test loop may never be executed if the termination condition is originally true.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Syntax
statement(s);
}
20ESCS101
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.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Flow diagram:
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Algorithm: Flowchart:
Step 1: Start.
otherwise go to step 7.
Step 5: f = f * i.
Step 6: Go to step 3.
Step 8: Stop.
20ESCS101
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:
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.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Flow diagram:
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Algorithm: Flowchart:
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);
} }
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
do {
statement(s);
do {
statement(s);
}while( condition );
}while( condition );
20ESCS101
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
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
endwhile
WRITE F1,F2
F=F1+F2
READ N
WHILE (F<N)
F=F1+F2
F1=F2
F2=F
WRITE F
END WHILE
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
video link
https://www.youtube.com/watch?v=nv52OwtCqIU
https://www.youtube.com/watch?v=vOEN65nm4YU