Fundamental Building Blocks of Computer: Unit: 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

ICCPL (Introduction to Computing and C- Programming language) : Notes

Unit: 1:
Fundamental building blocks of Computer
Main Memory
Memory enables a computer to store, at least temporarily, data and programs

Output Device
The results that are stored in the memory can be transformed into a form that can be understood by users
of a computer system by means of an output device. Some common output devices are monitor,
printer, speaker etc.

Mass storage Device


These devices allow computer to permanently retain large amounts of data. Common mass
storage device include disk drives and tape drives.

Central Processing Unit (CPU)


The CPU or processor is the brain of computer. It is the component that actually executes the
instructions. The CPU itself has three components, namely, arithmetic logic unit (ALU), control unit (CU),
and memory unit (MU).

Arithmetic Logic Unit:


-Arithmetic logic unit (ALU) performs two types of Operations i.e. arithmetic and logical.
Fundamental arithmetic operations include addition, subtraction, multiplication, and division.
Logical operations include comparisons like equal to, less than, greater than etc.

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes
Control Unit:
Control unit (CU) Coordinates and controls the operations of a computer system. It controls the activities
between memory and ALU and between CPU and input/output devices.

Memory Unit:
A memory unit (MU) is also called primary memory or main memory or RAM (random access
memory). It holds data for processing, instructions for processing data (program), and information
(processed data). The contents of main memory are lost when the computer is turned off.

Operating system (OS)


An operating system acts as an intermediary between the user of a computer and computer hardware. The
purpose of an operating system is to provide an environment in which a user can execute programs
conveniently and efficiently.

An operating system is software that manages computer hardware. The hardware must provide appropriate
mechanisms to ensure the correct operation of the computer system and to prevent user programs from
interfering with the proper operation of the system.

Operating System – Definition:

An operating system is a program that controls the execution of application


programs and acts as an interface between the user of a computer and the
computer hardware.

• A more common definition is that the operating system is the one program running at all times on
the computer (usually called the kernel), with all else being application programs.
• An operating system is concerned with the allocation of resources and services, such as memory,
processors, devices, and information. The operating system correspondingly includes programs to
manage these resources, such as a traffic controller, a scheduler, a memory management module,
I/O programs, and a file system.

Functions of Operating system – Operating system performs three functions:

1. Convenience: An OS makes a computer more convenient to use.


2. Efficiency: An OS allows the computer system resources to be used efficiently.
3. Ability to Evolve: An OS should be constructed in such a way as to permit the effective
development, testing, and introduction of new system functions at the same time without interfering
with service.
4. Throughput: An OS should be constructed so that It can give maximum throughput(Number of
tasks per unit time).

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes
Major Functionalities of Operating System:

• Resource Management: When parallel accessing happens in the OS means when multiple users
are accessing the system the OS works as Resource Manager, Its responsibility is to provide
hardware to the user. It decreases the load in the system.
• Process Management: It includes various tasks like scheduling, termination of the process. OS
manages various tasks at a time. Here CPU Scheduling happens means all the tasks would be done
by the many algorithms that use for scheduling.
• Storage Management: The file system mechanism used for the management of the storage. NIFS,
CFS, CIFS, NFS, etc. are some file systems. All the data stores in various tracks of Hard disks that
all managed by the storage manager. It included Hard Disk.
• Memory Management: Refers to the management of primary memory. The operating system has
to keep track, how much memory has been used and by whom. It has to decide which process needs
memory space and how much. OS also has to allocate and deallocate the memory space.
• Security/Privacy Management: Privacy is also provided by the Operating system by means of
passwords so that unauthorized applications can’t access programs or data. For example, Windows
uses Kerberos authentication to prevent unauthorized access to data.

The process operating system as User Interface:

1. User
2. System and application programs
3. Operating system
4. Hardware

Every general-purpose computer consists of the hardware, operating system, system programs, and
application programs. The hardware consists of memory, CPU, ALU, and I/O devices, peripheral devices,
and storage devices. System program consists of compilers, loaders, editors, OS, etc. The application
program consists of business programs, database programs.

Fig1: Conceptual view of a computer system

Every computer must have an operating system to run other programs. The operating system coordinates the
use of the hardware among the various system programs and application programs for various users. It
simply provides an environment within which other programs can do useful work.

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes
The operating system is a set of special programs that run on a computer system that allows it to work
properly. It performs basic tasks such as recognizing input from the keyboard, keeping track of files and
directories on the disk, sending output to the display screen, and controlling peripheral-devices.

OS is designed to serve two basic purposes:

1. It controls the allocation and use of the computing System’s resources among the various user and
tasks.
2. It provides an interface between the computer hardware and the programmer that simplifies and
makes it feasible for coding, creation, debugging of application programs.

The Operating system must support the following tasks. The tasks are:

1. Provides the facilities to create, modification of programs and data files using an editor.
2. Access to the compiler for translating the user program from high-level language to machine
language.
3. Provide a loader program to move the compiled program code to the computer’s memory for
execution.
4. Provide routines that handle the details of I/O programming.

I/O System Management –

The module that keeps track of the status of devices is called the I/O traffic controller. Each I/O device has a
device handler that resides in a separate process associated with that device. The I/O subsystem consists of

• A memory Management component that includes buffering caching and spooling.


• A general device driver interface.

Drivers for specific hardware devices-

Assembler –
The input to an assembler is an assembly language program. The output is an object program plus
information that enables the loader to prepare the object program for execution. At one time, the computer
programmer had at his disposal a basic machine that interpreted, through hardware, certain fundamental
instructions. He would program this computer by writing a series of ones and Zeros (Machine language),
place them into the memory of the machine.

Compiler –
The High-level languages- examples are FORTRAN, COBOL, ALGOL, and PL/I are processed by
compilers and interpreters. A compiler is a program that accepts a source program in a “high-level language
“and produces a corresponding object program. An interpreter is a program that appears to execute a source
program as if it was machine language. The same name (FORTRAN, COBOL, etc.) is often used to
designate both a compiler and its associated language.

Loader –
A Loader is a routine that loads an object program and prepares it for execution. There are various loading
schemes: absolute, relocating, and direct-linking. In general, the loader must load, relocate and link the
object program. The loader is a program that places programs into memory and prepares them for
execution. In a simple loading scheme, the assembler outputs the machine language translation of a program

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes
on a secondary device and a loader places it in the core. The loader places into memory the machine
language version of the user’s program and transfers control to it. Since the loader program is much smaller
than the assembler, those make more core available to the user’s program.

History of Operating system –


The operating system has been evolving through the years. The following table shows the history of OS.

Generation Year Electronic device used Types of OS Device


First 1945-55 Vacuum Tubes Plug Boards
Second 1955-65 Transistors Batch Systems
Third 1965-80 Integrated Circuits(IC) Multiprogramming
Fourth Since 1980 Large Scale Integration PC

Types of Operating System –

• Batch Operating System- Sequence of jobs in a program on a computer without manual


interventions.
• Time-sharing operating System- allows many users to share the computer resources. (Max
utilization of the resources).
• Distributed operating System- Manages a group of different computers and makes appear to be a
single computer.
• Network operating system- computers running in different operating systems can participate in a
common network (It is used for security purposes).
• Real-time operating system – meant applications to fix the deadlines.

Examples of Operating System are –

• Windows (GUI based, PC)


• GNU/Linux (Personal, Workstations, ISP, File and print server, Three-tier client/Server)
• macOS (Macintosh), used for Apple’s personal computers and workstations (MacBook, iMac).
• Android (Google’s Operating System for smartphones/tablets/smartwatches)
• iOS (Apple’s OS for iPhone, iPad, and iPod Touch)

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Software and its Types


In a computer system, the software is basically a set of instructions or commands that tells a computer what
to do. Or in other words, the software is a computer program that provides a set of instructions to execute a
user’s commands and tell the computer what to do. For example like MS-Word, MS-Excel, PowerPoint, etc.
The chart below describes the types of software:

Above is the diagram of types of software. Now we will briefly describe each type and its subtypes:

System Software

System software is software that directly operates the computer hardware and provides the basic
functionality to the users as well as to the other software to operate smoothly. Or in other words, system
software basically controls a computer’s internal functioning and also controls hardware devices such as
monitors, printers, and storage devices, etc. It is like an interface between hardware and user applications, it
helps them to communicate with each other because hardware understands machine language(i.e. 1 or 0)
whereas user applications are work in human-readable languages like English, Hindi, German, etc. so
system software converts the human-readable language into machine language and vice versa.

Features of system software:

Let us discuss some of the features of System Software:

1. System Software is closer to the computer system.


2. System Software is written in a low-level language in general.
3. System software is difficult to design and understand.
4. System software is fast in speed(working speed).
5. System software is less interactive for the users in comparison to application software.

Types of system software:

It has two subtypes which are:

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes
1. Operating System: It is the main program of a computer system. When the computer system ON it
is the first software that loads into the computer’s memory. Basically, it manages all the resources
such as memory, CPU, printer, hard disk, etc., and provides an interface to the user, which helps the
user to interact with the computer system. It also provides various services to other computer
software. Examples of operating systems are Linux, Apple macOS, Microsoft Windows, etc.
2. Language Processor: As we know that system software converts the human-readable language
into a machine language and vice versa. So, the conversion is done by the language processor. It
converts programs written in high-level programming languages like Java, C, C++, Python,
etc(known as source code), into sets of instructions that are easily readable by machines(known as
object code or machine code).
3. Device Driver: A device driver is a program or software that controls a device and helps that
device to perform its functions. Every device like a printer, mouse, modem, etc. needs a driver to
connect with the computer system eternally. So, when you connect a new device with your
computer system, first you need to install the driver of that device so that your operating system
knows how to control or manage that device.

Application Software

Software that performs special functions or provides functions that are much more than the basic operation
of the computer is known as application software. Or in other words, application software is designed to
perform a specific task for end-users. It is a product or a program that is designed only to fulfill end-users’
requirements. It includes word processors, spreadsheets, database management, inventory, payroll
programs, etc.

Features of application software:

Let us discuss some of the features of Application Software:

1. An important feature of application software is it performs more specialized tasks like word
processing, spreadsheets, email, etc.
2. Mostly, the size of the software is big, so it requires more storage space.
3. Application software is more interactive for the users, so it is easy to use and design.
4. The application software is easy to design and understand.
5. Application software is written in a high-level language in general.

Types of application software:

There are different types of application software and those are:

1. General Purpose Software: This type of application software is used for a variety of tasks and it is
not limited to performing a specific task only. For example, MS-Word, MS-Excel, PowerPoint, etc.
2. Customized Software: This type of application software is used or designed to perform specific
tasks or functions or designed for specific organizations. For example, railway reservation system,
airline reservation system, invoices management system, etc.
3. Utility Software: This type of application software is used to support the computer infrastructure. It
is designed to analyze, configure, optimize and maintains the system, and take care of its
requirements as well. For example, antivirus, disk fragmenter, memory tester, disk repair, disk
cleaners, registry cleaners, disk space analyzer, etc.

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes
Difference between system software and application software

Now, let us discuss some difference between system software and application software:

System Software Application Software


It is designed to manage the resources of the computer It is designed to fulfill the requirements of the user
system, like memory and process management, etc. for performing specific tasks.

Written in a low-level language Written in a high-level language

Less interactive for the users More interactive for the users

System software plays vital role for the effective Application software is not so important for the
functioning of a system. functioning of the system, as it is task specific.

It is independent of the application software to run. It needs system software to run.

ALGORITHM & FLOWCHART


ALGORITHM:

The word “algorithm” relates to the name of the mathematician Al-khowarizmi, which means a
procedure or a technique. Software Engineer commonly uses an algorithm for planning and solving
the problems. An algorithm is a sequence of steps to solve a particular problem or algorithm is an
ordered set of unambiguous steps that produces a result and terminates in a finite time

Algorithm has the following characteristics

• Input: An algorithm may or may not require input

• Output: Each algorithm is expected to produce at least one result

• Definiteness: Each instruction must be clear and unambiguous.

• Finiteness: If the instructions of an algorithm are executed, the algorithm should


terminate after finite number of steps

The algorithm and flowchart include following three types of control structures.

1. Sequence: In the sequence structure, statements are placed one after the other and the
execution takes place starting from up to down.
2. Branching (Selection): In branch control, there is a condition and according to a condition, a
decision of either TRUE or FALSE is achieved. In the case of TRUE, one of the two branches
is explored; but in the case of FALSE condition, the other alternative is taken. Generally, the
‘IF-THEN’ is used to represent branch control.
3. Loop (Repetition): The Loop or Repetition allows a statement(s) to be executed repeatedly
based on certain loop condition e.g. WHILE, FOR loops.

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Advantages of algorithm

• It is a step-wise representation of a solution to a given problem, which makes it easy to


understand.
• An algorithm uses a definite procedure.
• It is not dependent on any programming language, so it is easy to understand for anyone
even without programming knowledge.
• Every step in an algorithm has its own logical sequence so it is easy to debug.

HOW TO WRITE ALGORITHMS

Step 1 Define your algorithms input: Many algorithms take in data to be processed, e.g. to
calculate the area of rectangle input may be the rectangle height and rectangle width.

Step 2 Define the variables: Algorithm's variables allow you to use it for more than one place. We
can define two variables for rectangle height and rectangle width as HEIGHT and WIDTH (or H &
W). We should use meaningful variable name e.g. instead of using H & W use HEIGHT and WIDTH
as variable name.

Step 3 Outline the algorithm's operations: Use input variable for computation purpose,

e.g. to find area of rectangle multiply the HEIGHT and WIDTH variable and store the value in new
variable (say) AREA. An algorithm's operations can take the form of multiple steps and even branch,
depending on the value of the input variables.

Step 4 Output the results of your algorithm's operations: In case of area of rectangle output will be
the value stored in variable AREA. if the input variables described a rectangle with a HEIGHT of 2
and a WIDTH of 3, the algorithm would output the value of 6.

FLOWCHART:

The first design of flowchart goes back to 1945 which was designed by John Von Neumann. Unlike
an algorithm, Flowchart uses different symbols to design a solution to a problem. It is another
commonly used programming tool. By looking at a Flowchartone can understand the operations and
sequence of operations performed in a system. Flowchart is often considered as a blueprint of a design
used for solving a specific problem.

Advantages of flowchart:

• Flowchart is an excellent way of communicating the logic of a program.


• Easy and efficient to analyze problem using flowchart.
• During program development cycle, the flowchart plays the role of a blueprint, which makes
program development process easier.
• After successful development of a program, it needs continuous timely maintenance during
the course of its operation. The flowchart makes program or system maintenance easier.
• It is easy to convert the flowchart into any programming language code.

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Flowchart is diagrammatic /Graphical representation of sequence of steps to solve a problem. To


draw a flowchart following standard symbols are use

Symbol Name Symbol function

Used to represent start and


Oval end of flowchart

Parallelogram Used for input and output


operation

Processing: Used for


Rectangle arithmetic operations and
data-manipulations

Decision making. Used to


represent the operation in
Diamond which there are two/three
alternatives, true and false
etc

Flow line Used to indicate


Arrows the flow of logic by
connecting symbols

Circle Page Connector

Off Page Connector

Predefined Process
/Function Used to represent a
group of statements
performing one processing
task.

Preprocessor

|
--------- | Comments
|

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

The language used to write algorithm is simple and similar to day-to-day life language. The variable
names are used to store the values. The value store in variable can change in the solution steps. In
addition some special symbols are used as below

Assignment Symbol ( or =) is used to assign value to the variable.

e.g. to assign value 5 to the variable HEIGHT, statement is


HEIGHT 5

or
HEIGHT = 5
The symbol ‘=’ is used in most of the programming language as an assignment symbol, the same has
been used in all the algorithms and flowcharts in the manual.

The statement C = A + B means that add the value stored in variable A and variable B then
assign/store the value in variable C.

The statement R = R + 1 means that add I to the value stored in variable R and then assign/store the
new value in variable R, in other words increase the value of variable R by 1

Mathematical Operators:

Operator Meaning Example


+ Addition A+B
- Subtraction A–B
* Multiplication A*B
/ Division A/B
^ Power A^3 for A3
% Reminder A%B

Relational Operators

Operator Meaning Example


< Less than A<B
<= Less than or equal to A <= B
= or == Equal to A=B
# or != Not equal to A # B or A !=B
> Greater than A>B
>= Greater tha or equal to A >= B

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes
Logical Operators

Operator Example Meaning


AND A < B AND B < C Result is True if both A<B and
B<C are true else false
OR A< B OR B < C Result is True if either A<B or
B<C are true else false
NOT NOT (A >B) Result is True if A>B is false
else true

Selection control Statements

Selection Control Example Meaning


IF ( Condition ) Then IF ( X > 10 ) THEN If condition X>10 is True
… Y=Y+5 execute the statement
ENDIF ENDIF between THEN and ENDIF

IF ( Condition ) Then IF ( X > 10 ) THEN If condition X>10 is True


… Y=Y+5 execute the statement
ELSE ELSE between THEN and ELSE
….. Y=Y+8 otherwise execute the
Z=Z+3 statements between ELSE
ENDIF ENDIF and ENDIF

Loop control Statements

Selection Control Example Meaning


WHILE (Condition) WHILE ( X < 10) Execute the loop as long as
DO DO the condition is TRUE
.. print x
.. x=x+1
ENDDO ENDDO
DO DO Execute the loop as long as
…. print x the condition is false
… x=x+1
UNTILL (Condition) UNTILL ( X >10)

GO TO statement also called unconditional transfer of control statement is used to transfer control
of execution to another step/statement. . e.g. the statement GOTO n will transfer control to
step/statement n.

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes
Note: We can use keyword INPUT or READ or GET to accept input(s) /value(s) and keywords
PRINT or WRITE or DISPLAY to output the result(s).

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Algorithm & Flowchart to find the sum of two numbers

Algorithm

Step-1 Start

Step-2 Input first numbers say A


Step-3 Input second number say B
Step-4 SUM = A + B
Step-5 Display SUM
Step-6 Stop

OR

Algorithm

Step-1 Start

Step-2 Input two numbers say A & B


Step-3 SUM = A + B
Step-4 Display SUM

Step-5 Stop

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Algorithm & Flowchart to convert temperature from Celsius to Fahrenheit

C : temperature in Celsius F :
temperature Fahrenheit

Algorithm

Step-1 Start

Step-2 Input temperature in Celsius say C


Step-3 F = (9.0/5.0 x C) + 32
Step-4 Display Temperature in Fahrenheit F
Step-5 Stop

Algorithm & Flowchart to convert temperature from Fahrenheit to Celsius

C : temperature in Celsius F :
temperature Fahrenheit

Algorithm

Step-1 Start

Step-2 Input temperature in Fahrenheit say F


Step-3 C = 5.0/9.0 (F - 32 )
Step-4 Display Temperature in Celsius C

Step-5 Stop

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Algorithm & Flowchart to find Area and Perimeter of Square

L : Side Length of Square


AREA : Area of Square
PERIMETER : Perimeter of Square

Algorithm

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

Algorithm & Flowchart to find Area and Perimeter of Rectangle

L : Length of Rectangle B
: Breadth of Rectangle
AREA : Area of Rectangle PERIMETER
: Perimeter of Rectangle

Algorithm

Step-1 Start

Step-2 Input Side Length & Breadth say L, B


Step-3 Area = L x B
Step-4 PERIMETER = 2 x ( L + B)
Step-5 Display AREA, PERIMETER
Step-6 Stop

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Algorithm & Flowchart to find Area and Perimeter of Circle

R : Radius of Circle
AREA : Area of Circle Start

PERIMETER : Perimeter of Circle

Input Value
of R

Algorithm
AREA = 22.0/7.0
Step-1 Start
xRxR

Step-2 Input Radius of Circle say R


PERIMTER = 2 X
Step-3 Area = 22.0/7.0 x R x R 22.0/7.0 x R
Step-4 PERIMETER = 2 x 22.0/7.0 x R

Step-5 Display AREA, PERIMETER Print AREA,


Step-6 Stop PERIMTER

Stop

Algorithm & Flowchart to find Area & Perimeter of Triangle


(when three sides are given)

A : First Side of Triangle


B : Second Side of Triangle C
: Third Side of Triangle
AREA : Area of Triangle
PERIMETER : Perimeter of Triangle

Algorithm

Step-1 Start

Step-2 Input Sides of Triangle A,B,C


Step-3 S= (A + B + C)/ 2.0
Step-4 AREA = SQRT(S x (S-A) x (S-B) x(S-C))
Step-5 PERIMETER = S1 + S2 + S3
Step-6 Display AREA, PERIMETER
Step-7 Stop

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Algorithm & Flowchart to find Simple Interest

P : Principle Amount N
: Time in Years
R : % Annual Rate of Interest SI :
Simple Interest

Algorithm

Step-1 Start

Step-2 Input value of P, N, R


Step-3 SI = (P x N x R)/100.0
Step-4 Display SI F
Step-6 Stop

Algorithm & Flowchart to find Compound Interest

P : Principle Amount N
: Time in Years
R : % Annual Rate of Interest CI :
Compound Interest

Algorithm

Step-1 Start

Step-2 Input value of P, N, R C


Step-3 CI = P(1+R/100)N - P
Step-4 Display CI

Step-6 Stop

..

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Algorithm & Flowchart to Swap Two Numbers using Temporary Variable

Algorithm

Step-1 Start

Step-2 Input Two Numbers Say NUM1,NUM2 Step-3


Display Before Swap Values NUM1, NUM2
Step-4 TEMP = NUM1
Step-5 NUM1 = NUM2
Step-6 NUM2 = NUM1
Step-7 Display After Swap Values NUM1,NUM
Step-8 Stop

Algorithm & Flowchart to Swap Two Numbers without using temporary variable

Algorithm

Step-1 Start

Step-2 Input Two Numbers Say A,B Step-3


Display Before Swap Values A, B
Step-4 A=A+B
Step-5 B=A-B
Step-6 A=A-B
Step-7 Display After Swap Values A, B

Step-8 Stop

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Algorithm & Flowchart to find the smallest of two numbers

Algorithm

Step-1 Start

Step-2 Input two numbers say


NUM1,NUM2
Step-3 IF NUM1 < NUM2 THEN

print smallest is NUM1


ELSE
print smallest is NUM2
ENDIF
Step-4 Stop

Algorithm & Flowchart to find the largest of two numbers

Algorithm
Start

Step-1 Start

Step-2 Input two numbers say Input


NUM1,NUM2 Value of
Step-3 IF NUM1 > NUM2 THEN NUM1

print largest is NUM1


Input Value
ELSE
of NUM2
print largest is NUM2
ENDIF
Step-4 Stop Print Print
Yes if No
Largest is NUM1 > NUM2 Largest
is
NUM1 NUM2

Stop

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Algorithm & Flowchart to find the largest of three numbers

Algorithm

Step-1 Start

Step-2 Read three numbers say num1,num2, num3 Step-3


if num1>num2 then go to step-5
Step-4 IF num2>num3 THEN
print num2 is largest
ELSE
print num3 is largest
ENDIF
GO TO Step-6
Step-5 IF num1>num3 THEN
print num1 is largest ELSE
print num3 is largest
ENDIF
Step-6 Stop

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Algorithm & Flowchart to find the largest of three numbers (an another way)

Algorithm

Step-1 Start

Step-2 Read three numbers say A,B,C Step-


3 BIG = A
Step-4 IF B > BIG THEN

BIG = B
ENDIF
Step-5 IF C >BIG THEN

BIG = C
ENDIF
Step-6 Write BIG
Step-7 Stop

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Algorithm & Flowchart to find Even number between 1 to 50

Algorithm
Step-1 Start
Step-2 I=1
Step-3 IF (I >50) THEN
GO TO Step-7
ENDIF
Step-4 IF ( (I % 2) =0) THEN
Display I
ENDIF
Step-5 I=I+1
Step-6 GO TO Step--3
Step-7 Stop

Algorithm & Flowchart to find Odd numbers between 1 to n where n is a positive Integer

Algorithm

Step-1 Start

Step-2 Input Value of N


Step-3 I=1
Step-4 IF (I >N) THEN
GO TO Step-8
ENDIF
Step-5 IF ( (I % 2)=1) THEN
Display I
ENDIF
Step-6 I=I+1
Step-7 GO TO Step-4
Step-8 Stop

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

..

Algorithm & Flowchart to find sum of series 1+2+3+…..+N

Algorithm

Step-1 Start

Step-2 Input Value of N


Step-3 I = 1, SUM=0
Step-4 IF (I >N) THEN
GO TO Step-8
ENDIF
Step-5 SUM = SUM + I
Step-6 I=I+1
Step-7 Go to step-4
Step-8 Display value of SUM
Step-9 Stop

Algorithm & Flowchart to find sum of series 1+3+5+…..+N, Where N is positive odd Integer

Algorithm
Algorithm
Step-1 Start
Step-2 Input Value of N
Step-3 I = 1, SUM=0
Step-4 IF (I >N) THEN
GO TO step 8
ENDIF
Step-5 SUM = SUM + I
Step-6 I=I+2
Step-7 Go to step-4
Step-8 Display value of SUM
Step-9 Stop

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes
..

Algorithm & Flowchart to find sum of series 1 – X + X2 –X3 ….XN

Algorithm

Step-1 Start

Step-2 Input Value of N, X


Step-3 I = 1, SUM=1, TERM=1
Step-4 IF (I >N) THEN
GO TO Step-9
ENDIF
Step-5 TERM = - TERM * X
Step-6 SUM = SUM + TERM
Step-7 I=I+1
Step-8 Go to step-4
Step-9 Display value of SUM
Step-10 Stop

Algorithm & Flowchart to print multiplication Table of a number

Algorithm

Step-1 Start

Step-2 Input Value of NUM


Step-3 I=1
Step-4 IF (I >10) THEN
GO TO Step 9
ENDIF
Step-5 PROD = NUM * I

Step-6 WRITE I “x” NUM “=” PROD


Step-7 I=I+1
Step-8 Go to step-4
Step-9 Stop

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

..

Algorithm & Flowchart to generate first n Fibonacci terms 0,1,1,2,3,5…n (n>2)

Algorithm

Step-1 Start

Step-2 Input Value of N

Step-3 A=0, B=1, COUNT=2


Step-4 WRITE A, B
Step-5 IF (COUNT >N) then go to step 12
Step-6 NEXT= A + B
Step-7 WRITE NEXT

Step-8 A=B
Step-9 B=NEXT
Step-10 COUNT=COUNT + 1

Step-11 Go to step-4
Step-12 Stop

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Algorithm & Flowchart to find sum and average of given series of numbers

Algorithm

Step-1 Start

Step-2 COUNT=0
Step-3 SUM=0
Step-4 Input NUM (next number in series)
Step-5 SUM= SUM +NUM
Step-6 COUNT=COUNT+1

Step-7 IF More Number in Series then


GOTO Step-4
ENDIF

Step-8 AVERGAE=SUM / COUNT


Step-9 WRITE SUM, AVERAGE
Step-10 Stop

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Algorithm & Flowchart to find Roots of Quadratic Equations AX2+BX+C=0

Algorithm

Step-1 Start

Step-2 Input A,B,C


Step-3 DISC= B2 – 4 A * C
Step-4 IF (DISC < 0) THEN
Write Roots are Imaginary
Stop
ENDIF
Step-5 IF (DISC==0) THEN
Write Roots are Real and Equal
X1 = - B/(2*A)
Write Roots are X1,X1
Stop
ENDIF
Step-6 IF (DISC >0)

Write Roots are Real and Unequal


X1= (- B + SQRT(DISC)) / (2*A)
X2= (- B + SQRT(DISC)) / (2*A)
Write Roots are X1,X2
Stop
ENDIF

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Algorithm & Flowchart to find if a number is prime or not

Algorithm

Step-1 Start

Step-2 Input NUM


Step-3 R=SQRT(NUM)
Step-4 I=2

Step-5 IF ( I > R) THEN


Write NUM is Prime Number
Stop
ENDIF
Step 6 IF ( NUM % I ==0) THEN
Write NUM is Not Prime
Stop
ENDIF
Step-7 I=I+1
Step-8 Go to Step-5

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Algorithm & Flowchart to find GCD and LCM of two numbers

Algorithm

Step-1 Start
Step-2 Read two number A, B
Step-3 IF (A > B) THEN
N =A
D=B
ELSE
N=B
D=A
ENDIF
Step-4 r=N/D

Step-5 WHILE (r != 0)
DO
N=D
D=r
r =N%D
DONE

Step-6 gcd=d
Step-7 lcm = (a*b)/gcd
Step-8 Display gcd, lcm
Step-9 Stop

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Algorithm & Flowchart to find Factorial of number n ( n!=1x2x3x…n)

Algorithm

Step-1 Start

Step-2 Read number N

Step-3 FACT=1 CTRL=1 Step-4


WHILE (CTRL <= N)
DO
FACT=FACT*I
CTRL=CTRL+1
DONE
Step-5 Display FACT
Step-6 Stop

Algorithm & Flowchart to find all the divisor of a number

Algorithm

Step-1 Start
Step-2 Read number N
Step-3 D=1
Step-4 WHILE (D< N)
DO
IF ( N % D ==0) THEN PRINT
D
ENDIF
D=D+1
DONE
Step-5 Stop

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

Compilation and Execution Process

Generally coding is done in high level language or low level language (assembly language). For the
computer to understand these languages, they must be translated into machine level language. The
translation process is carried out by a compiler/interpreter (for high level language) or an assembler (for
assembly language program). The machine language code thus created can be saved and run immediately
or later on.

In an interpreted program, each program statement is converted into machine code before program is
executed. The execution occurs immediately one statement at a time sequentially. BASIC is one of the
frequently used interpreted language. In contrast to interpreter, a compiler converts a given source code
into object code. Once an object code is obtained, the compiled programs can be faster and more efficient
than interpreted programs.

Compilation Process

A source code must go through several steps before it becomes an executable program. In the first step
the source code is checked for any syntax errors. After the syntax errors are traced out a source file is
passed through a compiler which first translates high level language into object code (A machine code not
ready to be executed). A linker then links the object code with pre-compiled library functions, thus
creating an executable program. This executable program is then loaded into the memory for execution.
General compilation process is shown in Figure below:

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes
Difference between Linker and Loader

In execution of the program, major role is played by two utility programs known as Linker and Loader.

1. Linker :
A linker is special program that combines the object files, generated by compiler/assembler, and other
pieces of codes to originate an executable file have. exe extension. In the object file, linker searches and
appends all libraries needed for execution of file. It regulates the memory space that will hold the code
from each module. It also merges two or more separate object programs and establishes link among them.
Generally, linkers are of two types :

1. Linkage Editor
2. Dynamic Linker

2. Loader:
The loader is special program that takes input of executable files from linker, loads it to main memory,
and prepares this code for execution by computer. Loader allocates memory space to program. Even it
settles down symbolic reference between objects. It is in charge of loading programs and libraries in
operating system. The embedded computer systems don’t have loaders. In them, code is executed through
ROM. There are following various loading schemes:

1. Absolute Loaders
2. Relocating Loaders
3. Direct Linking Loaders
4. Bootstrap Loaders

Difference between Linker and Loader:

S.No. LINKER LOADER


The main function of Linker is to generate Whereas main objective of Loader is to load
1
executable files. executable files to main memory.
The linker takes input of object code generated And the loader takes input of executable files
2
by compiler/assembler. generated by linker.
Linking can be defined as process of Loading can be defined as process of loading
3 combining various pieces of codes and source executable codes to main memory for further
code to obtain executable code. execution.
Linkers are of 2 types: Linkage Editor and Loaders are of 4 types: Absolute, Relocating,
4
Dynamic Linker. Direct Linking, Bootstrap.
Another use of linker is to combine all object It helps in allocating the address to executable
5
modules. codes/files.
Linker is also responsible for arranging objects Loader is also responsible for adjusting references
6
in program’s address space. which are used within the program.

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes
Editors & its Types

Editors are basically computer programs that are utilised to edit files on a computer. The provide
environment to a programmer to create, edit, update, format a document in any order he/she wants to.

In system programming or programming, editors are software or tools that are used to edit the
program. These are basically text editors of special type that have integrated functionality to edit code.

Some common program editors are notepad++, visual code, sublime. Also there are some edits that
provide things used to do more than just editing the code. They are the integrated development
environment (IDE) which can help you edit, debug and run your program in the same software.

Back to editors which have evolved so long and have been around, since the evolution of modern
computers has begun.

Editors based on how it edits the file

GRAPHICAL EDITOR− A special editor which is used to edit a graphical file or a photo. These work
based on the fact that pixels of a photo can be edited and changed.

TEXT EDITOR− This editor edits text files and updates their characters and format.

Type of editor based on who it edits the file

LINE EDITOR− This code editor edits the file line by line. You cannot work on a stream of lines using
the line editor. Example of a line editor is teleprinter.

STREAM EDITOR− This code editor edits the file by treating them as a sequence of characters to work
on instead of treating it as a single line. Using a stream editor, you can work on paragraphs. Example of a
stream editor is Sed Editor.

SCREEN EDITOR− This editor is able to edit any character on screen. Editor can update the content by
clicking on it using the cursor and then update the content in any way required.

WORD PROCESSOR− This is an advanced editor, one which you might have worked on (currently).
The word processor editing software is used to perform all editing tasks and also perform special
operations like editing fonts, adding styles, size features and adding multimedia to it like inserting
images, files, videos.

STRUCTURE EDITOR− This editor is specially used to edit programs that need structuring of code. It
provides features of writing and editing source code and provides an environment.

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes
Types of Compilers

A compiler transforms and translates a high-end language to machine (low level) understandable
language. The compiling process does basic translation mechanisms and also error detection. The front
end compilation includes lexical, syntax, and semantic analysis. And at the back end, the compilation
does the code generation and optimization. So there are many compilers in C like BDS, Clang, GCC,
Interactive C, Lattice, Portable C Compiler, Visual Express, etc. Let’s get to know more about a few of
them.

Explanations to C Compilers

Below are the Top Compilers of C:

1) Borland Turbo C

Turbo C is one of the basic and popular compilers for the C programming language. This was first
introduced in 1987; it was popular for its small size, compilation speed, and low price. Once Turbo C++
got released in 1990, both the compilers are merged and the name Turbo C got discontinued. In 2006,
Embarcadero Technologies had re-released Turbo C as freeware. Do you remember this blue screen?

2) Tiny C Compiler

The Tiny C Compiler is designed to work on slow computers with little disk space. This is an ARM
processor C compiler. This compiler started its support to Windows from 2005. Some of its features are
mentioned below.

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes
1. Its file size is small and according to the owner of this compiler (Fabrice Bellard). The fastness of
this compiler is around nine times faster than GCC. The compilation, assembling and linking of
code were the main attributes considered for measuring the fastness of this compiler.
2. This compiler had included many compiler-specific features to boost up the optional memory,
bound checker and had greater code stability.
3. This compiler allows automatic execution of programs during the compile-time only using
command line arguments. This way, programs are executed under UNIX, using shell scripts. The
latest version was released on December 2017.

3) Portable C Compiler

The Portable C Compiler (PCC) was a very early used and established compiler for the C programming
language that is almost around mid-1970. This compiler had a long life span. This was prevalent during a
period in such a way that many of the C compilers were based on it. The advantages of PCC depended on
its capabilities and probability predictions. PCC compiler was made such that source files were machine-
dependent, not all but only a few of them. It can detect syntax errors and can perform perfect validity
checks. A new version of PCC was released on 10 December 2014.

4) GCC

GNU Compiler Collection is the compiler produced by the GNU Project. This supports many
programming languages and it is a free software foundation under the General Public License. This
compiler was first released in 1987 and it supported only C- Programming language during the start.
Slowly it expanded to C++, Java, Android, and IOS. Here, each of the different language compilers has
its own program that reads the code written and sends the machine code as the output. All of these have a
common internal structure. When a high-level language is written, as per the language it is written, the
compiler parses the code in that language and produces an abstract syntax tree. GCC uses LALR parsers,
but slowly switched to recursive-descent parsers for C in 2006. Coming to the optimization part, as
already known this can occur during any phase of the compilation. However, here the bulk optimizations
are performed before the code generation and after the syntax, semantic analysis. Below are a few of the
optimizations performed by GCC.

1. It can eliminate the Dead Code pieces.


2. It can eliminate the redundancy at the code level.
3. Replacement of Aggregates with respect to the scalar level.
4. Can perform optimizations with Arrays.

In GCC back end is specified by preprocessor macros and functions specific to a particular architecture.
This code is generally built by first calling a small snippet code which is associated with each pattern and
generate instructions from the instruction set. It is done using registers, offsets, and addresses that are
chosen during the re-load phase. The current version of GCC is 9.2, which was released on August 12,
2019.

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes
5) Clang

1. Clang; including C, is also a compiler for C++, Objective-C, and objective-C++ programming
languages. This compiler uses LLVM for the back end code related compilations. This compiler
has been designed to act as a replacement for the GCC by supporting many of its compilation
flags and language extensions.
2. Clang has many contributors including Apple, Microsoft, Google, Sony, and Intel. It is open-
source software. LLVM was first used by GCC for the front end compilation, but GCC had
caused some problems for developers at Apple, as the source code is large and difficult to use. So,
they had come up with Clang.
3. One of the major goals for Clang is to provide library-based architecture. It is designed to keep
more information during the compilation process than GCC. This also helps to preserve the
overall shape of the original code.
4. The error report generated by Clang during compilation is always in a detailed and specific in a
machine-readable format. Clang had always aimed to reduce the over usage of memory space and
increase the compilation speed as compared with GCC, and due to these qualities, it had become
one of the fastest-growing used compilers during a point of time. But over a period the
performance of Clang started to come down. The reports told the performance had lagged with
almost large differences as compared with GCC and started to have slower performance. The
most recent comparisons indicate that both the compilers had come up and increased their
performance and once again creating great competition between them. Yet, GCC remains to top
the list.

Flow of C Program
The C program follows many steps in execution. To understand the flow of C program well, let
us see a simple program first.

File: simple.c

1. #include <stdio.h>
2. int main(){
3. printf("Hello C Language");
4. return 0;
5. }

Let's try to understand the flow of above program by the figure given below.
1) C program (source code) is sent to preprocessor first. The preprocessor is responsible to
convert preprocessor directives into their respective values. The preprocessor generates an
expanded source code.

2) Expanded source code is sent to compiler which compiles the code and converts it into
assembly code.

3) The assembly code is sent to assembler which assembles the code and converts it into object

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes
code. Now a simple.obj file is generated.

4) The object code is sent to linker which links it to the library such as header files. Then it is
converted into executable code. A simple.exe file is generated.

5) The executable code is sent to loader which loads it into memory and then it is executed.
After execution, output is sent to console.

Execution Flow

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)
ICCPL (Introduction to Computing and C- Programming language) : Notes

By, Dr. Amit Gadekar & Mritunjay Kr. Ranjan. (SOET-Sandip University, Nashik.)

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