How to develop a program:::
Program development is the process of creating application programs. The program
development life cycle (PDLC) is the process that contains the six phases of program development:
analyzing, designing, coding, debugging, testing, and documentation and maintaining
application software.It is an iterative process.
The following are six steps in the Program Development Life Cycle:
1. Analyze the problem. The computer user must figure out the problem, need to completely
comprehend problem, and then has to decide how to resolve the problem.
2. Design the program. A flow chart is important to use during this step of the PDLC. This is a visual
diagram of the flow containing the program. This step will help you break down the problem. we
can also use algorithms.
3. Code the program. This is using the language of programming to write the lines of code. The code
is called the listing or the source code. The computer user will run an object code for this step.
4. Debug the program. The computer user must debug. This is the process of finding the "bugs" on
the computer and fix them.
5. Testing the program(Formalize the solution) One must run the program to ensure no runtime and
logic(semantic) errors.
6. Document and maintain the program. This step is the final step of gathering everything together.
Internal documentation is involved in this step because it explains the reason one might have made
a change in the program or how to write a program. Later given to the user, during a long run, it
might encounter issues that are to be resolved by the developer.
Algorithm:
An algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain
order to get the desired output. Algorithms are generally created independent of underlying languages,
i.e. an algorithm can be implemented in more than one programming language.
There are no well-defined standards for writing algorithms. Algorithms are never written to support a
particular programming code.
characteristics of an Algorithm
An algorithm has the following characteristics:
Input: An algorithm requires some input values. An algorithm can be given a value other than 0 as
input.
Output: At the end of an algorithm, you will have one or more outcomes.
Unambiguity(definiteness): A perfect algorithm is defined as unambiguous, which means that its
instructions should be clear and straightforward.
Finiteness: An algorithm must be finite. Finiteness in this context means that the algorithm should
have a limited number of instructions, i.e., the instructions should be countable.
Effectiveness: Because each instruction in an algorithm affects the overall process, it should be
adequate. Every step must be basic and has to essential.
Language independence: An algorithm must be language-independent, which means that its
instructions can be implemented in any language and produce the same results.
Advantages and disadvantages of an Algorithm
Designing an algorithm has following advantages :
Effective Communication: Since algorithm is written in English like language, it is simple
to understand step-by-step solution of the problems.
Easy Debugging: Well-designed algorithm makes debugging easy so that we can identify
logical error in the program.
Easy and Efficient Coding: An algorithm acts as a blueprint of a program and helps during
program development.
Independent of Programming Language: An algorithm is independent of programming
languages and can be easily coded using any high level language.
An algorithm has following disadvantages :
Developing algorithm for complex problems would be time consuming and difficult to
understand.
Understanding complex logic through algorithms can be very difficult.
Now, use an example to learn how to write algorithms.
Problem 1: Create an algorithm that multiplies two numbers and displays the output.
Step 1 − Start
Step 2 − declare three integers x, y & z
Step 3 − define values of x & y
Step 4 − multiply values of x & y
Step 5 − store result of step 4 to z
Step 6 − print z
Step 7 − Stop
Problem 2: Create an algorithm that finds an area of a circle for a given radius and displays the output.
Step 1 − Start
Step 2 − declare two variables radius and area
Step 3 − define the value for the radius
Step 4 – using the formula pi*r*r calculate area (note :: pi=3.147)
Step 5 − store the result of step 4 to the area
Step 6 − print the area
Step 7 − Stop
Problem 3: Create an algorithm that finds whether the given geometric shape is square or rectangle then
find its area and perimeter and display the output.
Step 1 − Start
Step 2 − declare four variables length, breadth, area, and perimeter
Step 3 − define the value for length and breadth
Step 4 – if length==breadth then it is square goto step 5 else it is a rectangle goto step
6
Step 5 – using the formula 4*length for perimeter and length*length for the area,
calculate the perimeter and area of a square, go to step 7
Step 6 – using the formula 2*(length+breadth) for perimeter and length*breadth for
the area, calculate the perimeter and area of a rectangle, go to step 7
Step 7 − store the result of step 5 or step 6 in the perimeter and area depending on the
decision
Step 8 – print the perimeter and area
Step 9 – Stop
Problem 4: Create an algorithm that finds the sum of the first n natural numbers and displays the output.
Step 1 − Start
Step 2 – Declare variables n, sum and i
Step 3 – Define variable n, sum =0 and i=1
Step 4 –Repeat step 4 to 6 until i <= n
Step 5 –Update sum as sum = sum + i
Step 6 –Increment i
Step 7 –Print sum
Step 8 – Stop
Exercise::
Problem 5: Create an algorithm that finds the largest among two numbers and displays the output.
Problem 6: Create an algorithm that finds an average of 5 numbers and displays the output.
Problem 7: Create an algorithm that finds the roots of the quadratic equation ax2 + bx + c = 0 and
displays the output.
Problem 8: Create an algorithm that interchange the value of two numbers and displays the output.
Flowchart :
A flowchart is a diagrammatic representation of sequence of logical steps of a program.
Flowcharts use simple geometric shapes to depict processes and arrows to show relationships and
process/data flow.
Flowchart Symbols
Here is a chart for some of the common symbols used in drawing flowcharts.
Symbol Symbol Name Purpose
Used at the beginning and end of the algorithm to show
Start/Stop
start and end of the program.
Process Indicates processes like mathematical operations.
Input/ Output Used for denoting program inputs and outputs.
Stands for decision statements in a program, where
Decision answer is usually Yes or No.
Shows relationships between different shapes.
Arrow
Connects two or more parts of a flowchart, which are on
On-page Connector
the same page.
Connects two parts of a flowchart which are spread over
Off-page Connector
different pages.
Guidelines for Developing Flowcharts
These are some points to keep in mind while developing a flowchart −
Flowchart can have only one start and one stop symbol
On-page connectors are referenced using numbers
Off-page connectors are referenced using alphabets
General flow of processes is top to bottom or left to right
Arrows should not cross each other
Now, use an example to learn how to draw a flowchart.
Problem 1: A flowchart that multiplies two numbers
Problem 2: A flowchart that finds an area of a circle for a given radius.
Problem 3: A flowchart that finds whether the given geometric shape is square or rectangle then find its
area and perimeter.
Start
Read length (l)
& breadth (b)
True False
If
(l==b)?
Perimeter=4*l Perimeter=2*(l+b)
Area=l*l Area=l*b
Print area
and
perimeter
Stop
Problem 4: A flowchart that finds sum of first N natural numbers displays the output.
Exercise::
Problem 5: A flowchart that finds largest among two numbers .
Problem 6: A flowchart that finds average of 5 numbers .
Problem 7: A flowchart that finds roots of quadratic equation ax2 + bx + c =0.
Problem 8: A flowchart that interchange the value of two numbers.
Difference between Algorithm and Flowchart::
On the basis of Algorithm Flowchart
Basic An algorithm is a step-by-step The Flowchart is the most widely used
method for solving some problem. graphical representation of an algorithm
An algorithm refers to a set of and procedural design workflows. It uses
instructions that define the various symbols to show the operations and
execution of work to get the decisions to be followed in a program.
expected results.
Comprehensibility Algorithm is hard to understand. Flowchart is easy to understand.
Implementation There are no rules employed for Predefined rules are implemented for
algorithms. flowcharts.
Symbols used It uses plain text, which is written in It uses symbols such as parallelogram,
plain English language. rectangle, diamond, etc.
Debugging Algorithms are easy to debug. Flowcharts are hard to debug.
Nature Algorithms are the program's Flowcharts are the graphical
pseudocode. representation of logic.
Branching and In algorithms, it is easy to show In Flowcharts, branching and looping are
looping branching and looping. difficult to represent.
Psuedo code
It's simply an implementation of an algorithm in the form of annotations and informative text written
in plain English. It has no syntax like any of the programming language and thus can't be compiled or
interpreted by the computer.
Pseudo code, as the name suggests, is a false code or a representation of code which can be understood
by even a layman with some school level programming knowledge.
Pseudocode is an intermediate state between algorithm and program that plays supports the transition
of the algorithm into the program.
Key Points To Note
A pseudocode is not bound to a programming language but is subjective and non-standard.
It is just a learning and reasoning tool that programmers and developers use to underline how
to write the actual code.
Unlike a programming language code, it does not follow a strict structure and syntax.
Use appropriate naming conventions.
Reserved commands or keywords must be represented in capital letters. Example: if you are
writing IF…ELSE statements then make sure IF and ELSE be in capital letters.
Check whether all the sections of a pseudo code are complete, finite, and clear to understand
and comprehend. Also, explain everything that is going to happen in the actual code.
If using loops or conditionals, indent the line of code. .
Here are some reasons to use pseudocode:
Easier to read: Developers often work closely with other professionals, such as product owners,
managers, etc., with little to no programming knowledge. However, using pseudocode
makes it easy for them to understand the flow and mechanics of a program’s, website’s, or
app’s source code. It facilitates easy communication between different professionals.
Simplifies code construction: Code generation becomes extremely easy and quick with
pseudocode.
Middle point: A middle point between an algorithm and the actual code.
Quick bug detection: As it is written in simple English, uncovering bugs without writing code
becomes more effortless. Also, you can make changes to it anytime quickly.
Special Keyword
BEGIN,END: To begin and end the pseudocode.
INPUT : Take input from the user.
PRINT: To print the output on the screen.
READ/GET: Input format while reading data from the file.
SET, INIT: Initialize a value.
INCREMENT, BUMP: Increase the value of the variable, equivalent to a++.
DECREMENT: Decrease the value of the variable, equivalent to a--.
Problem 1: Create an algorithm that multiplies two numbers and displays the output.
BEGIN
DECLARE x, y, z AS INTEGER
PRINT "Enter two numbers: "
INPUT x
INPUT y
z ←x * y
PRINT "Product = ", z
END
Problem 2: Create an algorithm that finds an area of a circle for a given radius and displays the output.
BEGIN
DECLARE radius, area AS REAL
PRINT "Enter radius"
INPUT radius
area ←3.147 * radius * radius
PRINT "Area of circle = ", area
END
Problem 3: Create an algorithm that finds whether the given geometric shape is square or rectangle then
find its area and perimeter and display the output.
BEGIN
DECLARE length, breadth, area, perimeter AS REAL
PRINT "Enter length: "
INPUT length
PRINT "Enter breadth: "
INPUT breadth
IF length = breadth THEN
// It is a square
perimeter ←4 * length
area ←length * length
ELSE
// It is a rectangle
perimeter ←2 * (length + breadth)
area ←length * breadth
ENDIF
PRINT "Perimeter = ", perimeter
PRINT "Area = ", area
END
Problem 4: Create an algorithm that finds the sum of the first n natural numbers and displays the
output.
BEGIN
DECLARE n, sum, i AS INTEGER
PRINT "Enter n: "
INPUT n
sum ←0
i ←1
WHILE i <= n DO
sum ←sum + i
i ←i + 1
ENDWHILE
PRINT "Sum of first n natural numbers = ", sum
END
Exercise::
Problem 5: A Pseudo code that finds largest among two numbers .
Problem 6: A Pseudo code that finds average of 5 numbers .
Problem 7: A Pseudo code that finds roots of quadratic equation ax2 + bx + c =0.
Problem 8: A Pseudo code that interchange the value of two numbers.
pseudocode to a program involves translating the high-level, human-readable logic into the
specific syntax and semantics of a chosen programming language. This process can be broken down
into several steps:
Understand the Pseudocode:
Thoroughly analyze the pseudocode to grasp the algorithm's purpose, the flow of control, the data being
manipulated, and the desired output. Break down complex pseudocode into smaller, more manageable
logical units.
Choose a Programming Language:
Select the programming language (e.g., C,Python, C++, Java, JavaScript) in which the program will be
implemented. This choice will dictate the specific syntax and libraries available.
Identify Key Elements and Translate:
Variables: Declare variables in the chosen language corresponding to those identified in the
pseudocode, ensuring appropriate data types.
Control Flow: Translate control flow statements (e.g., IF-THEN-ELSE, WHILE-DO, FOR loops) into
their equivalent syntax in the target language. Pay close attention to indentation and block
structuring, especially in languages like Python where it's syntactically significant.
Operations: Convert arithmetic, logical, and other operations into the correct operators and
function calls of the chosen language.
Input/Output: Implement input and output operations using the language's specific functions or
methods for user interaction and displaying results.
Implement the Logic:
Write the actual code, line by line, translating each pseudocode instruction into its programming
language equivalent. This involves applying the syntax and conventions of the chosen language while
maintaining the original algorithmic logic.
Test and Debug:
After converting the pseudocode into code, rigorously test the program with various inputs to ensure it
functions as intended and produces the correct output. Use debugging techniques to identify and
resolve any errors or inconsistencies between the pseudocode's logic and the program's behavior.
Write a C program that finds whether the given geometric shape is square or rectangle then find its area
and perimeter and display the output.
#include <stdio.h>
int main() {
float length, breadth, area, perimeter;
// Input values
printf("Enter length: ");
scanf("%f", &length);
printf("Enter breadth: ");
scanf("%f", &breadth);
// Check if square or rectangle
if (length == breadth) {
// Square
perimeter = 4 * length;
area = length * length;
printf("It is a Square\n");
}
else {
// Rectangle
perimeter = 2 * (length + breadth);
area = length * breadth;
printf("It is a Rectangle\n");
}
// Output results
printf("Perimeter = %.2f\n", perimeter);
printf("Area = %.2f\n", area);
return 0;
}
Different types of errors in programming languages:
Errors are the problems or faults that occur in the program, which make the behavior of the program
abnormal, and experienced developers can also make these faults. Programming errors are also known
as bugs or faults, and the process of removing these bugs is known as debugging.
These errors are detected either during the time of compilation or execution. Thus, the errors must be
removed from the program for the successful execution of the program.
Syntax error:: Syntax errors are also known as compilation errors as they occur at the compilation time,
or we can say that the syntax errors are thrown by the compilers. These errors mainly occur due to
mistakes while typing or do not follow the syntax of the specified programming language. These
mistakes are generally made by beginners only because they are new to the language. These errors can
be easily debugged or corrected.
Commonly occurred syntax errors are:
o If we miss the parenthesis (}) while writing the code.
o Displaying the value of a variable without its declaration.
o If we miss the semicolon (;) at the end of the statement.
Run-time error:: Sometimes the errors exist during the execution time even after the successful
compilation known as run-time errors. When the program is running, and it is not able to operate is
the main cause of the run-time error.
The division by zero is a common example of the run-time error. Array index out of bounds, string
index out of bounds, etc., are also the most frequent run-time errors. These errors are very difficult to
find, as the compiler does not point to these errors.
Semantic errors ::Semantic errors are the errors that occurred when the statements are not
understandable by the compiler or error that leads to an undesired output.
The following can be the cases for the semantic error:
Use of a un-initialized variable.
int i;
i=i+2;
Type compatibility
int b = "javatpoint";
Errors in expressions
int a, b, c;
a+b = c;
Array index out of bound
int a[10];
a[10] = 34;