0% found this document useful (0 votes)
13 views11 pages

Chapter 1b 8-12-2022

Uploaded by

creatorbeing09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views11 pages

Chapter 1b 8-12-2022

Uploaded by

creatorbeing09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Chapter1: Introduction to Programming

 Evolution of Programming Languages,


 The compilation process
 Object, source, and executable code
 Fundamentals of Algorithms
 Flowcharts

1. Compilation process in c
What is a compilation?
The compilation is a process of converting the source code into object code. It is done with the help of the
compiler. The compiler checks the source code for syntactical or structural errors, and if the source code
is error-free, then it generates the object code. The c compilation process converts the source code taken
as input into the object code or machine code.

The compilation process can be divided into four steps, i.e., Pre-processing, Compiling, Assembling, and
Linking
o Pre-processor
 The preprocessor takes the source code as input, and removes all the comments from the
source code, and expands the code.
 The preprocessor takes the preprocessor directive and interprets it.
 The source code is written in the editor and it has an extension “.c”
For example, if <stdio.h>, the directive is available in the program, then the preprocessor interprets
the directive and replaces this directive with the content of the 'stdio.h' file.
o Compiler
The code which is expanded by the preprocessor is passed to the compiler. The compiler converts
this code into assembly code.
o Assembler
The assembly code is converted into object code by using an assembler. The name of the object file
generated by the assembler is the same as the source file.
Eg. If the name of the source file is 'hello.c', then the name of the object file would be 'hello.obj'.

o Linker
 The job of the linker is to link the object code of our program with the object code of the
library files and other files.
 The output of the linker is the executable file.
 The name of the executable file is the same as the source file but differs only in their
extensions
For example, For example, if we are using printf() function in a program, then the linker adds its
associated code in an output file
Let's understand through an example.
hello.c
1. #include <stdio.h>
2. int main()
3. {
4. printf("Hello world");
5. return 0;
6. }
Now, we will create a flow diagram of the above program:

The following steps are taken to execute a program:


o Firstly, the input file, i.e., hello.c, is passed to the preprocessor, and the preprocessor converts the
source code into expanded source code. The extension of the expanded source code would be hello.i.
o The expanded source code is passed to the compiler, and the compiler converts this expanded source
code into assembly code. The extension of the assembly code would be hello.s.
o This assembly code is then sent to the assembler, which converts the assembly code into object code.
o After the creation of an object code, the linker creates the executable file. The loader will then load
the executable file for the execution
2. Algorithm
An algorithm is a set of well-defined instructions to solve a particular problem. If, it is written in
English like sentences then, it is called as ‘PSEUDO CODE’. It takes a set of input(s) and produces
the desired output.

For example,
Algorithm 1: Add two numbers entered by the user
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
Step 5: Compute sum←num1+num2
Step 6: Display sum
Step 7: Stop
Algorithm 2: Finding the average of three numbers −
Step 1: Start
Step 2: Declare variables a, b, and c.
Step 3: Read 3 numbers a,b,c
Step 4: Compute sum = a+b+c
Step 5: Compute average = sum/3
Step 6: Display average value
Step 7: Stop

3. Flowchart

 The Flowchart is the most widely used graphical representation of an algorithm and procedural
design workflows.
 It uses various symbols to show the operations and decisions to be followed in a program.
 It flows in sequential order.

Types of Flowcharts
The various types of flowcharts are given below.
 Horizontal Flowchart
 Panoramic Flowchart
 Vertical Flowchart
 Architectural Flowchart

Rules or guidelines of Flowchart:


 Only conventional flowchart symbols should be used.
 Proper use of names and variables in the flowchart.
 If the flowchart becomes large and complex, use connector symbols.
 Flowcharts should have start and stop points.
Flowchart symbols:
The different flowchart symbols have different conventional meanings.

Symbol Symbol Name Purpose

Used at the beginning and end of the algorithm


Start/Stop
to show the start and end of the program.

Indicates processes like mathematical


Process operations.

Input/ Output Used for denoting program inputs and outputs.

Stands for decision statements in a program,


where the answer is usually Yes or No.
Decision

Shows relationships between different shapes.


Arrow

Connects two or more parts of a flowchart,


which are on the same page.
On-page Connector

Connects two parts of a flowchart which are


spread over different pages.
Off-page Connector

The various symbols used in Flowchart Designs are given below.

 Terminal Symbol: In the flowchart, it is represented with the help of a circle for denoting the
start and stop symbol

 Input/output Symbol: The input symbol is used to represent the input data, and the output
symbol is used to display the output operation.
 Decision Symbol: Diamond symbol is used for represents decision-making statements.

 Connector Symbol: The connector symbol is used if flows discontinued at some point and
continued again at another place.

 Flow lines: It represents the exact sequence in which instructions are executed. Arrows are
used to represent the flow lines in a flowchart.

 Hexagon symbol (Flat): It is used to create a preparation box containing the loop setting
statement.

 On-Page Reference Symbol: This symbol contains a letter inside that indicates the flow
continues on a matching symbol containing the same letters somewhere else on the same
page.

 Off-Page Reference: This symbol contains a letter inside indicating that the flow continues
on a matching symbol containing the same letter somewhere else on a different page.
 Delay or Bottleneck: This symbol is used for identifying a delay in a flowchart. The
alternative name used for the delay is the bottleneck.

 Internal storage symbol:

Advantages of Flowchart in C:
o Communication: A flowchart is a better way of communicating the logic of a program.
o Efficient Coding: Flowcharts act as a guide for a programmer in writing the actual code
in a high-level language.
o Proper Debugging: Flowcharts help in the debugging process.
o Effective Analysis: Effective analysis of logical programs can be easily done with the
help of a related flowchart.
o Proper Documentation: Flowchart provides better and proper documentation. It consists
of various activities such as collecting, organizing, storing, and maintaining all related
program records.
o Testing: A flowchart helps in the testing process.
o Efficient program maintenance: The maintenance of the program becomes easy with the
help of a flowchart.

Disadvantages of Flowchart in C:
o Time-consuming: Designing a flowchart is a very time-consuming process.
o Complex: It isn't easy to draw a flowchart for large and complex programs.
o There is no standard in the flowchart; there is no standard to determine the quantity of
detail.
o Difficult to modify: It is very difficult to modify the existing flowchart.
Examples of flowchart:
The various examples of the flowchart are given below:
Example 1: Design a flowchart for adding two numbers entered by the user.

Example 2: Design a flowchart for finding the largest among three numbers entered by the user.
Example 3: Design a flowchart for calculating the profit and loss according to the value entered by the user.

Example 4: Draw a flowchart to calculate the average of two numbers.


Example 5: Design a flowchart for the multiplication of three numbers entered by the user.

Example 6: Design a flowchart for calculating the area of a rectangle.


Example 7: Design a flowchart for calculating the Simple Interest according to the value entered by the user.

Example 8: Design a flowchart for checking whether the number is positive or negative according to the
number entered by the user.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy