CLASS - 1
1.0 Programming Methodology and Introduction to C Language
1.1. State different steps involved in problem solving
1.2. Define algorithm and know its characteristics
1.3. Define a program and differentiate between program and algorithm
1.4. State the steps involved in algorithm development
1.5. Differentiate algorithm and flowchart
1.6. Develop algorithms for simple problems
1.7. Draw the symbols used in flowcharts and draw flowcharts for simple problems
Unit – 1
Programming Methodology
1.1 Steps involved in problem solving
Problem Solving:
Problem solving is the act of defining a problem; determining the cause of the problem;
identifying, prioritizing, and selecting alternatives for a solution; and implementing a solution
Computers play an important role in problem solving. We communicate with a computer though
some programming language. But before we start the programming, the problem to be solved requires
some analysis, i.e., preparation.
Problem solving steps
The various steps in problem solving (analysis) are as follows:
1. Studying the problem in detail.
2. Understand carefully the given input and what output is required. Also identify the conditions
and constraints to be used.
3. Generating various methods of solution of the given problem.
4. Selecting the method which is considered to be the best.
5. Preparing sequential steps for determining the solution.
6. Write a program to compute the results as using a computer and get the results.
Steps 1 to 4 relate to the problem analysis. Step 5 provides a logical, sequence of steps required for
solving a problem. This introduces the algorithmetic approach to problem solving.
1.2 Algorithms:
Definition: An algorithm is a step-by-step procedure/method for solving a problem or making decisions.
Or
An algorithm is a finite sequence of well defined steps for solving a problem.
Characteristics of Algorithm
An algorithm has five important characteristics: Inputs: An algorithm may specify the quantities which are to be read. Outputs: An algorithm must specify the quantities which are to be displayed or printed. Definiteness: Each instruction must be clear and unambiguous. Finiteness: An algorithm should be terminated after finite number of steps. Effectiveness: An algorithm must be effective which means that all operations are
executable. Language Independent: The Algorithm designed must be language-independent, i.e. it
must be just plain instructions that can be implemented in any language, and yet the
output will be same, as expected.
Algorithm Development
To solve a problem on a computer. We need to identify the inputs and outputs to state the
problem in a precise manner,
The steps involved in developing algorithm are:
1. Identification of the nature of the problem and requirements.
2. Identification of the variables that are involved.
3. Identification of the relationship between the variables.
4. Problem formulation and analysis.
5. Identification of method of solving the problem.
6. Checking the results.
In solving a problem or computer programs we used to follow a systematic approach. There
may be much number of algorithms in solving a problem, but we can select a particular
algorithm, which we can follow it with ease, just as selecting an easy way to reach a wanted
destination.
Advantages of Algorithms:
• It is easy to understand.
• Algorithm is a step-wise representation of a solution to a given problem.
• 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:
• Writing an algorithm takes a long time so it is time-consuming.
• Branching and looping statements are difficult to show in Algorithms.
1.3 Program
Definition
A computer program is a collection of instructions that can be executed by a computer to
perform a specific task.
• A computer program is usually written by a computer programmer in a programming
language. From the program in its human-readable form of source code, a compiler or
assembler can derive machine code a form consisting of instructions that the computer
can directly execute.
• Each computer language has its own set of rules called syntax rules. We have to use the
exact syntax rules of the computer language whenever we write any computer program.
There is a close analogy between learning English language and learning C language. The
classical method of learning English is to first learn the alphabets used in the language, then
learn to combine these alphabets to form words, which in turn are combined to form sentences
and sentences are combined to form paragraphs
Learning C is similar and easier. Instead of straight-away learning how to write
programs, we must first know what alphabets, numbers and special symbols are used in C, then
how using them constants, variables and keywords are constructed, and finally how are these
combined to form an instruction. A group of instructions would be combined later on to form a
program.
Differentiate between program and algorithm
Program
• A computer program is a collection of instructions that can be executed by a computer to
perform a specific task.
• Programs are written at Implementation time.
• For writing programs we use only Programming language like C, C++, Java, Python.
• It is dependent on hardware/ Operating System.
• After wring the program we do testing (run and check the program).
Algorithm
• An algorithm is a step-by-step procedure/method for solving a problem or making
decisions.
• Algorithms are written at Design time.
• We can use any language (English language or mathematical notation) to write an
algorithm.
• When we are going to write an algorithm, we don’t bother hardware (hw)/Operating
system (OS).
• After writing an algorithm, we analyze the algorithm :
(a)Are we achieving the results perfectly or not?
(b) Checking the efficiency of the algorithm in terms of time and space
Algorithms for simple problems
1. Write an algorithm to find the sum of four given numbers?
Step 1: Start
Step 2: Read values of A, B, C, D
Step 3: Compute sum = A+B+C+D
Step 4: Print the values of sum
Step 5: Stop
2. Write an algorithm to find the average of four given numbers?
Step 1: Start
Step 2: Read values of A, B, C, D
Step 3: Compute average = (A+B+C+D)/4
Step 4: Print the values of average
Step 5: Stop
3. Write an algorithm for calculating the simple interest.
Formula of Interest=PTR/100, where P is the Principle amount, R is the rate of interest and T is
the time.
Step 1: Start
Step 2: Read values of P, T, R
Step 3: Compute I = P*T*R/100
Step 4: Print the values of P,T,R,I
Step 5: Stop
1.4 Flowcharts
Definition:
A flowchart is a diagrammatic representation that shows the sequence of operations to be
performed to get the solution of a problem.
A flowchart is the graphical or pictorial representation of an algorithm with the help of
different symbols, shapes, and arrows to demonstrate a process or a program. With algorithms, we
can easily understand a program. The main purpose of using a flowchart is to analyze different
methods. Several standard symbols are applied in a flowchart.
Flowchart Symbols ;
1. Oval
• It is called as Terminal symbol
• It is used for beginning and ending point of the program.
2. Parallelogram
• It is called as input/output symbol
• It indicates an input or output operation
Advantages of Flowchart
1. It is a convenient method of communication.
2. It indicates very clearly just what is being done, where a program has logical complexities.
3. A key to correct programming.
4. It is an important tool for planning and designing a new system.
5. It clearly indicates the role-played at each level.
6. It saves the inconveniences in future and serves the purpose of documentation for a system.
7. It provides an overview of the system and also demonstrates the relationship between various
steps.
Disadvantages of Flowchart
1. The flowchart is a waste of time and slows down the process of software development.
2. Sometimes the Complex logic of the program logic is quite complicated to draw out on by
using different defined shapes. In that case, flowchart becomes complex and clumsy.
3. A correction in the logic of the given problem can require redrawing the entire flowchart.
4.It is hard to debug errors.
5.The solution is showcased in pictorial format. 6.It costs less time to create a flowchart.
Algorithm
• An algorithm is a procedure for solving a problem.
• The process is shown in step-by-step instruction.
• It is complex and difficult to understand.
• It is convenient to debug errors.
• This solution is showcased in natural language.
• It costs more time to create an algorithm.
Flowcharts for simple problems
Draw a flowchart to calculate the circumference and area of a circle
Draw a flowchart to find the largest of 3 given numbers
1.5 Loops
Definition:
Computers are most useful when they are used to repeat the same calculations for large
number of times. A loop is a set of instructions which are to be repeated a fixed number of times
or until some condition is met.
Looping
Looping refers to the repeated use of one or more steps of computation. Computers are most
useful when they are used to repeat a set of steps for larger number of times.
There are two types of loops:
a. Fixed loop
In a fixed loop, the operations are repeated for a known number of times. The values
of variables inside the loop have no effect on the number of times the loop is repeated.
b. Variable loop.
In a variable loop, the operations are repeated until a specified condition is met.
1.6 Branching
The process of branching of the main path of flow into two or more paths and joining together
after some steps of actions of at least before stop/end is known as branching.
• Normally the branching is done from a decision box in which the basis of selection of
a particular path is stated.
• The decision can be based on a comparison, on the value of expressions, on the sign of
a variable, etc
0 Comments