0% found this document useful (0 votes)
6 views9 pages

C Prog Govt Poly Unit 1 Algorithm&Flowchart

The document provides an introduction to algorithms in C programming, defining algorithms as step-by-step processes to solve specific problems. It outlines the characteristics, advantages, and disadvantages of algorithms, as well as steps to develop them. Additionally, it discusses flowcharts as a graphical representation of algorithms, including their advantages, disadvantages, and guidelines for preparation.

Uploaded by

AKHIL JAISWAL
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
6 views9 pages

C Prog Govt Poly Unit 1 Algorithm&Flowchart

The document provides an introduction to algorithms in C programming, defining algorithms as step-by-step processes to solve specific problems. It outlines the characteristics, advantages, and disadvantages of algorithms, as well as steps to develop them. Additionally, it discusses flowcharts as a graphical representation of algorithms, including their advantages, disadvantages, and guidelines for preparation.

Uploaded by

AKHIL JAISWAL
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 9

C Programming- Govt. Poly.

CS/IT
Unit 1- Introduction to C Programming
Prof. Akhil M. Jaiswal
9028637523

Fundamentals Of Algorithms:

Define Algorithm:

“Algorithm is a Step by Step Process written in simple English language


defined to perform some specific operation in order to solve some
problem.”

Algorithm is “A step by step logic used to solve some specific problem for a defining a
program”. Therefore Algorithm refers to a set of rules/instructions that step-by-step define
how a work is to be executed upon in order to get the expected results.

Prof. Akhil M. Jaiswal Page 1


Algorithms help to do a task in programming to get the expected output. The Algorithm
designed are language-independent, i.e. they are just plain instructions that can be
implemented in any language, and yet the output will be the same, as expected.

Characteristics of an Algorithm : What are the Characteristics of an Algorithm?


Not all written instructions for programming is an algorithm. In order for some
instructions to be an algorithm, it must have the following characteristics:

Following are the Important Characteristics of Algorithm :

1. Well-Defined Inputs : If an algorithm says to take inputs, it should be well-


defined inputs. An algorithm must accept zero for more inputs.
2. Well-Defined Outputs : The algorithm must clearly define what output is
expected and it should be well-defined as well.
3. Definiteness: Algorithm should be clear and unambiguous. Each of its steps
should be clear in all aspects and must lead to only one meaning.
4. Finite-ness: The algorithm must have finite number of steps & must terminate
after it, i.e. it should not end up in infinite loops.
5. Effectiveness: Each instruction should have proper feasible meaning &
effectiveness to produce desired result.
6. Language Independent: The Algorithm designed must be language-
independent, i.e. it must be just plain instructions in English that can be

Prof. Akhil M. Jaiswal Page 2


implemented in any Programming language, and yet the output will be same,
as expected.

Advantages of Algorithms:
 It is easy to Understand, Write & Debug.
 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.

Steps in developing Algorithm : How to Design an Algorithm?

In order to write an algorithm, following things are needed as a pre-requisite:

1. Define the Problem: First the problem must be defined in clear words that need to be solved.
2. Identifying Inputs: The Data inputs required to solve the problem must be identified & defined.
3. Identifying Outputs: The Expected Result from the algorithm must be Identified & specified.
4. Identifying Steps: The set of all steps required to process the input & generate expected output
must be defined & each step in the algorithm should be carried out easily.

Example of Algorithms:
1) Algorithm to calculate square of a given number.

Algorithm: Square

Input: A Number

Output: Display Value of Square

Step 1: Start

Step 2: Declare Variable NUM, SQUARE

Step 3: Read value for NUM

Step 4: [Multiply NUM to itself & assign result to SQUARE]

SQUARE  NUM * NUM

Step 5: Display the value of SQUARE

Step 6: Stop

2) Algorithm to calculate Area of Circle

Algorithm: Area of Circle


Prof. Akhil M. Jaiswal Page 3
Input: Radius of Circle
Output: Display Area of Circle
Step 1: Start
Step 2: Declare Variable RADIUS, AREA
Step 3: Read value for RADIUS
Step 4: [Calculate the Area of Circle & assign result to AREA]
AREA  3.14* RADIUS * RADIUS
Step 5: Display the value of AREA
Step 6: Stop

3) Algorithm to determine If a given number is EVEN or ODD (W-19)

Algorithm: EVEN or ODD


Input: A Number
Output: Display Message of EVEN or ODD
Step 1: Start
Step 2: Declare Variable NUM
Step 3: Read value for NUM
Step 4: If NUM%2==0
Display “NUM is EVEN”
else
Display “NUM is ODD”
Step 5: Stop
4) Write an algorithm to determine whether a given number is divisible by 5 or not. (W-18)

Algorithm: Divisible by 5 or NOT


Input: A Number
Output: Display Message of Divisible by 5 or NOT
Step 1: Start
Step 2: Declare Variable NUM
Step 3: Read value for NUM
Step 4: If NUM%5==0
Display “NUM is Divisible by 5”
else
Display “NUM is NOT Divisible by 5”
Step 5: Stop

Prof. Akhil M. Jaiswal Page 4


5) Write algorithm and draw flow-chart to print even numbers from 1 to 100. (W-18)

Algorithm: Display Even numbers from 1 to 100


Input: NIL
Output: Display all Even numbers from 1 to 100
Step 1: Start
Step 2: Declare Variable I
Step 3: Initialize Variable
I1
Step 4: Repeat the Steps until I < = 100
4.1: If I%2==0
Display Value of I
4.2: II+1
Step 5: Stop
6) Write algorithm to find greatest of 3 Numbers.

Algorithm: Greatest of 3 Numbers


Input: 3 Integer Numbers
Output: Display Greatest of 3 Numbers
Step 1: Start
Step 2: Declare Variable NUM1, NUM2, NUM3
Step 3: Read value for NUM1, NUM2, NUM3
Step 4: if NUM1>NUM2:
if NUM1>NUM3:
Display “NUM1 is Greatest”
else
Display “NUM3 is Greatest”
else if NUM2>NUM3:
Display “NUM2 is Greatest”
else
Display “NUM3 is Greatest”
Step 5: Stop

Flowchart: The Flowchart is the graphical representation of an algorithm. It uses various symbols
to show the operations and decisions to be followed in a program. In other words, It’s the pictorial
representation drawn for logic display before the program to be written.

Advantages of Flowchart in C: Following are the various advantages of flowchart:


1. Communication: A flowchart is a better way of communicating the logic of a program.
2. Easy to Understand: Since It is based on pictorial representation, it is easy to understand.
Prof. Akhil M. Jaiswal Page 5
3. Efficient Coding: Flowcharts act as a guide for a programmer in writing the actual code in a
high-level language.
4. Proper Debugging: Flowcharts help in the debugging process.
5. Effective Analysis: Effective analysis of logical programs can be easily done with the help of
a related flowchart.
6. Proper Documentation: Flowchart provides better and proper documentation.
7. Testing: A flowchart helps in the testing process.
8. Efficient program maintenance: The maintenance of the program becomes easy with the
help of a flowchart.

Disadvantages of Flowchart in C: Following are the various disadvantages of


flowchart:

1. Time-consuming: Designing a flowchart is a very time-consuming process.


2. Complex: It isn't easy to draw a flowchart for large and complex programs.
3. There is no standard in the flowchart; there is no standard to determine the quantity of
detail.
4. Difficult to modify: It is very difficult to modify the existing flowchart.

Symbols of Flowchart: Flowchart is basically a pictorial or diagrammatic


representation of an algorithm using standard symbols as listed below:

Guidelines for Preparing Flowchart:


1. Standard symbols should be used while drawing flowchart.

Prof. Akhil M. Jaiswal Page 6


2. Each flowchart starts with START (or BEGIN) symbol and STOP (or END) symbol.
3. All Symbols are connected with flow-lines/ arrow lines ( )
4. Only one flow line should enter process symbol.
5. Only one flow line should come out from process symbol.
6. Flowchart should be neat, clean and easy to follow. There should be no any
ambiguity.
7. The usual direction of flowchart is from top to bottom.
8. Each Flowchart ends with End/STOP Symbol.

Examples of flowcharts:

1. Flowchart for Addition of two numbers entered by the user.

Declare variables n1, n2 & sum

Display value of sum

2. Find the largest among three different numbers entered by the user.

Declare variables a, b & c

Display “b is Greatest” Display “c is Greatest” Display “a is Greatest”

3. Flowchart to calculate Square of given Number


Prof. Akhil M. Jaiswal Page 7
START

Declare Variables
NUM & SQUARE

Accept value for


NUM from User

Calculate SQUARE= NUM* NUM

Display Value of NUM

STOP

4. Flowchart to calculate Area of Circle


START

Declare Variables
RADIUS & AREA

Accept value for RADIUS


from User

Calculate AREA= 3.14 * RADIUS* RADIUS

Display Value of AREA

STOP

5. Flowchart to Find Largest of two Numbers.


START

Declare Variables
NUM1 & NUM2

Accept value for NUM1 &


NUM2 from User

If NUM1 >NUM2

Display “NUM1 Is Greater” Display “NUM2 Is Greater”

STOP

Prof. Akhil M. Jaiswal Page 8


Prof. Akhil M. Jaiswal
Ph.d (Scholar), ME(CSE), BE(IT)
C, C++, Java, Advance Java, Python, Android,
DBMS, RDBMS, Computer Hardware,
Data Structure, Discrete Structure, Software
Engineering, Software Testing etc.
All Computer/IT/Electronics Subjects
9028637523
akhilmjaiswal@gmail.com

Prof. Akhil M. Jaiswal Page 9

You might also like