0% found this document useful (0 votes)
14 views

C - Notes Unit-1

Uploaded by

Suyash Shukla
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

C - Notes Unit-1

Uploaded by

Suyash Shukla
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Computer System and Programming in C (RCS-101/201)

Unit-1
Computer:
• It is an electronic device which takes input (Data), processes it and produces the output (Information).

Digital Computer:
A digital computer is a digital system that performs various computational tasks. The word digital implies 
the info in computer is shown by variables that take a limited no. of discrete values. Then these values are processed
internally by components and discrete states are maintained.
Ist electronic digital computer developed in-1940. It was used mainly for numerical computations. In this case
the discrete elements are digits. So from this place we got the term- “Digital Computer.”
These machines (m/c) cooperate efficiently if only ‘2’ states are used.
Bit: Digital computers use the binary no. system, which has two digits: 0, 1.
A binary digit ≡ ‘bit’.
So information is represented in digital computers in group of bits.
By this group of bits we can not only represent binary nos. but also other discrete symbols (decimal
digits/letter/alphabet) can be shown with the help of many coding techniques. Further more development of symbols
& sets of Instructions (program) are also possible for doing many computations with the proper arrangement of bits.
(Coding methods)
Sarvesh Kr. Soni (Asst. Prof., Dept. of IT) 1
Computer System

Software Hardware
(instruction, data, Application) (Electronic components, electromech. Devices)

Digital Computer
A computer is an electronic machine like any other machine which takes inputs (raw data) and performs some
processing giving out processed data (information).

Block Diagram of Digital computer

1. Input: This is the process of entering data and programs in to the computer system. Therefore, the input unit takes
data from us to the computer in an organized manner for processing.

2. Storage: The process of saving data and instructions permanently is known as storage. Data has to be fed into the
system before the actual processing starts. It is because the processing speed of Central Processing Unit (CPU) is so
fast that the data has to be provided to CPU with the same speed. Therefore the data is first stored in the storage unit
for faster access and processing. This storage unit or the primary storage of the computer system is designed to do
the above functionality. It provides space for storing data and instructions.

The storage unit performs the following major functions:


• All data and instructions are stored here before and after processing.
• Intermediate results of processing are also stored here.

3. Processing: The task of performing operations like arithmetic and logical operations is called processing. The
Central Processing Unit (CPU) takes data and instructions from the storage unit and makes all sorts of calculations
based on the instructions given and the type of data provided. It is then sent back to the storage unit.

Sarvesh Kr. Soni (Asst. Prof., Dept. of IT) 2


4. Output: This is the process of producing results from the data for getting useful information. Similarly the output
produced by the computer after processing must also be kept somewhere inside the computer before being given to
you in human readable form. Again the output is also stored inside the computer for further processing.

5. Control: The manner how instructions are executed and the above operations are performed. Controlling of all
operations like input, processing and output are performed by control unit. It takes care of step by step processing of
all operations inside the computer.

FUNCTIONAL UNITS

In order to carry out the operations mentioned in the previous section the computer allocates the task between its
various functional units. The computer system is divided into three separate units for its operation. They are

1) Arithmetical logical unit 2) control unit. 3) Central processing unit.

• Arithmetical Logical Unit (ALU): After you enter data through the input device it is stored in the primary
storage unit. The actual processing of the data and instruction are performed by Arithmetic Logical Unit. The
major operations performed by the ALU are addition, subtraction, multiplication, division, logic and
comparison. Data is transferred to ALU from storage unit when required. After processing the output is
returned back to storage unit for further processing or getting stored.
• Control Unit (CU) The next component of computer is the Control Unit, which acts like the supervisor seeing
that things are done in proper fashion. Control Unit is responsible for coordinating various operations using
time signal. The control unit determines the sequence in which computer programs and instructions are
executed. Things like processing of programs stored in the main memory, interpretation of the instructions
and issuing of signals for other units of the computer to execute them. It also acts as a switch board operator
when several users access the computer simultaneously. Thereby it coordinates the activities of computer’s
peripheral equipment as they perform the input and output.

Central Processing Unit (CPU) The ALU and the CU of a computer system are jointly known as the central
processing unit. You may call CPU as the brain of any computer system.
Computer H/w : It can be divided into 3 major parts
1. CPU
2. Memory (RAM)
3. I/O Processor

CPU has →
o Arithmetical & logical unit for data manipulation.
o No. of registers for data-storage
o Control circuits to fetch & execute Instructions.

MEMORY UNITS:- The memory of C.P.U. is register which is very small and very fast and also costly. Hence it
needed memory for storing information. Generally two type of memory uses in computer systems.

1. Main memory also called primary memory.


2. Secondary memory

1. PRIMARY MEMORY (MAIN MEMORY):- Main memory is directly access by C.P.U. RAM (Random
Access Memory made of semiconductor) are used as main memory. It is called Random because C.P.U. can
access any location of memory any time. Its access time 10 nano second (n.s.).
Other semiconductor memory is ROM (Read Only Memory. ROM is permanents memory, difference can
be understands as bellow.)

Sarvesh Kr. Soni (Asst. Prof., Dept. of IT) 3


TYPESOF RAM:- Basically two types of RAM exits.

1. Static RAM → SRAM


2. Dynamic RAM → DRAM

STATIC RAM:- The static RAM retain information as long power supply is on. Static RAM made of D flip –
flops without use of capacitor. There is no need to refresh it. It is faster and costly than D-RAM.
DYNAMIC RAM:- Dynamic RAM are made of transistors and capacitor. Since capacitor has leakage property
hence it needed charge at random time (for few second).That’s why it is called dynamic RAM. Slower but higher
capacity than DRAM.

DIFFERENCE BETWEEN SPRM AND DRAM


S.N. SRAM DRAM
1. SRAM made of flip-flops. DRAM made of transistors and capacitors.
2. SRAM needs 6 transistors for storing DRAM needs only one transistor fop storing
3. bits. 1 bit.
SRAM is costly, 6 transistors require DRAM is cheaper only one transistor require
for R/W facility. for R/W facility.

Any RAM can be faster by using Cache memory between C.P.U. register and main memory. Another RAM is
EDO RAM → Extended data output RAM
SDRAM → Synchronous DRAM (Same clock
SGRAM → Synchronous Graphics RAM rate a C.P.U )
DDRSDRAM → Double Data Rate DRAM (Transfer data from both edges of clocks )

Random Access Memory (RAM) Read Only Memory (ROM)


1. It is volatile memory i.e. when 1. ROM is permanent. The stored information does
power goes off the stored information not loss while power supply goes off. Also called
lost. non volatile.
2. RAM possessor random manner 2. ROM not possessor random manner (but may be).
i.e. any information access randomly. 3. ROM can not write it can read only.
3. RAM is read /writes memory i.e. 4. ROM less costly as compare to RAM for large
any information access Randomly. volume.
4. RAM is much costly as compared
to ROM large volume.

ROM:- Rom is stand for read only memory.


It is nonvolatile memory. The information stored in it is not lost even if power supply goes off is used for
permanent storage. It also possesses Random property. ROM is accessible to users. The contents of Rom decided
by manufacturers ROMS store monitor, assembler, debugging package, function table such as sine, cosine,
logarithm, square root, etc. Example of RAM
Toshiba Mask ROM
TCS 534000, 512kx 8 bits
TYPES OF ROM
PROM:- Stand for programmable ROM. Its content decided by user not manufacturer. User can store information
by special equipment called Prom programmer. PROM is more costly. Example:- 745287
EPROM:- Stand for erasable PROM. The stored information can erased by exposing it to high intensity short wave
ultraviolet light about 20 minutes. It not convenient be causing for removing information from EPROM it is
necessary separate EPROM from chip.

Sarvesh Kr. Soni (Asst. Prof., Dept. of IT) 4


EEPROM:- It is stand for Electrically erasable PROM also known as EAPROM (Electrically alterable
PROM).The information can erase byte by byte. It limit for any EEPROM again a few milliseconds. There is limit
for any EEPROM again and again reprogrammed. EPROM requires 21 volt pulse for writing or erasing and 5 volt
for read operations.

Basic Hardware Components

Software

Program: A sequence of instructions for the computer is called a program. The data that are manipulated by
the program create the database.

1. System software-It is the software used to manage and control the hardware components and which allow
interaction between the hardware and the other types of software. The most obvious type of system software
is operating system and device drivers.
Utility software-It is software such as anti-virus software, firewalls, disk defragmenters and so on.
which helps to maintain and protect the computer system but does not directly interface with the hardware.
2. Applications software (also known as 'apps') are designed to allow the user of the system to complete a
specific task(application). They include programs such as web browsers, MS office, games, media players
and so on.

Sarvesh Kr. Soni (Asst. Prof., Dept. of IT) 5


Memory Hierarchy

Speed Memory Description

Registers are embedded inside the CPU. They have very less capacity but
fastest speed. CPU uses some specific registers like PC (program counter), IR
Fastest Register
(instruction register), MAR (memory address register), MDR (memory data
register) and some GPR (general purpose registers),Ax(Accumulator register).

Cache memory is memory actually embedded inside the CPU. Cache memory
is very fast, typically taking only once cycle to access, but since it is
Faster Cache embedded directly into the CPU there is a limit to how big it can be. In fact,
there are several sub-levels of cache memory (termed L1, L2, L3) all with
slightly increasing speeds.

All instructions and storage addresses for the processor must come from
Slower RAM. Although RAM is very fast, there is still some significant time taken
than RAM for the CPU to access it (this time is latency). RAM is stored in separate,
Cache dedicated chips attached to the motherboard, meaning it is much larger than
cache memory.

We are all familiar with software arriving on a floppy disk or CDROM, and
saving our files to the hard disk. We are also familiar with the long time a
Slowest Disk program can take to load from the hard disk -- having physical mechanisms
such as spinning disks and moving heads means disks are the slowest form of
storage. But they are also by far the largest form of storage.

FLOPPY DISC:- Floppy disc have single disc and R/W heads in floppy
Disc drive. The sized floppy disc is 1.44MB.Two type of floppy disc depend on size.

1. 3.5 INCH FLOPY DISC 1.44 MB


2. 5 INCH FLOPY DISC

Sarvesh Kr. Soni (Asst. Prof., Dept. of IT) 6


Now a day 7/2 inch disc are using 5 inch disc are not used today. Both drive require different drive for read and
write operations.
3.5 inch drive denoted by drive ‘A’
5 inch drive denoted by drive ‘B’

OPTICAL DEVICES: Optical disc is same as magnetic disc but it does not contain magnetic foil at its surface.
The optical disc made by other type of materials. A disc surface PIT and LAND made by laser beam. The PIT
denote ‘1’ and LAND denote ‘0’ .When laser beam exposing on surface of disc by R/W head. The reflected beam
suffer different distance from PIT and LAND as shown in figure .By this property head can differentiate between
PIT (1) and LAND (0).

MEGNETIC DISC:- Magnetic disc include floppy disc and hard disc. Working principle of both is same. Data
stores on disc surface. Its surfaces divided into co centric track and each track divided into sectors. The disc is
mounted on a rotary drive (D.C. Motor) to rotate disc. After read data R/W head remains stationary, while disc
rotate continuously. All
tracks contain same number of bytes. Hence track which is nearer to centre is denser (complex) than outer tracks. A
disc may other structure that a sector contains different no. of tracks.
Hard disc is combination of more disc in co centric frame as shown below. Read/write Head. The data can be
access only with read/write heads. All disc are rotating continuously and head move forward and backward
direction as required. Size of hard disc is varying in few GB now in TB.

CACHE MEMORY: - Cache memory placed between C.P.U. and main memory. It consists of static RAM. Its
access time is about 10 n.s. Cache memory help to provide data to C.P.U. as needed. Since Ram can not provide as
speed as C.P.U. need, so Cache are use to remove this difficulty.

SECONDARY MEMORY: - Secondary memory is also known as permanent strong. It stores files (Text, Audio,
Video etc) and other format of data. The stored file transfer from secondary memory to Primary memory when
needed by computer for execution of any program because any file can not executed in secondary memory it can be
executed any Primary memory (RAM).Two type of Secondary memory used today

o Magnetic memory
o Optical memory

MAGNETIC MEMORY: - Magnetic memory is not volatile it is used for backup memory. Digital data 0 and 1
store on magnetic coating film. The binary digit depends on direction of magnetization of very small area of
magnetic film. There are two technique used for storing data.

o Longitudinal recording
o Vertical recording

Operating System
An O.S. acts as an intermediary between the user of a computer S/W & the computer H/w.
“The purpose of an O.S. is to provide an event. in which a user can execute programs in a convenient &
efficient manner.”
O.S. is a S/w which controls or operates the H/w of computer.
H/w of computer : CPU, memory, I/O devices Etc. (touch & feel)
S/w of computer : Packages for different applications.
: Compliers of different Languages
: Others, Information/data (e-mail, …)
So O.S. is just like a government, it does nothing (important) useful functions by itself. It only provides an environment
within which other programs can do useful work.

Sarvesh Kr. Soni (Asst. Prof., Dept. of IT) 7


An operating system, or "OS," is a system software that communicates with the hardware and allows other programs
to run. It has the fundamental files your computer needs to boot up and function. Every desktop computer, tablet, and
smart phone includes an operating system that provides basic functionality for the device.
e.g MS DOS, Win 95 ,win 2000,win xp, win 8, Unix, Linux, Android etc.

Important functions of an operating system:


• Memory Management
• Processor Management
• Device Management
• File Management
• Security Management
• Control over system performance
• Job accounting
• Error detecting aids
• Coordination between other software and users

Types of operating systems:

1. Batch OS :The users of batch operating system do not interact with the computer directly. Each user prepares
his job on an off-line device like punch cards and submits it to the computer operator. Main problems are -
Lack of interaction between the user and job, CPU is often idle.

2. Real-time OS: A real-time operating system is a multitasking operating system that aims at executing real-
time applications. Real-time operating systems often use specialized scheduling algorithms so that we can
perform multiple tasks simultaneously. The main objective of real-time operating systems is their quick and
predictable response to events. They have an event-driven or time-sharing design. Ex- VxWorks, MARS,
RTLinux

3. Multi-user OS: A multi-user operating system allows multiple users to access a computer system at the same
time. Time-sharing systems and Internet servers can be classified as multi-user systems. Single-user operating
systems have only one user but may allow multiple programs to run at the same time.Ex-UNIX,Main-
Frame,Supercomputer.

4. Distributed OS: A distributed operating system manages a group of independent computers and makes them
appear to be a single computer. The development of networked computers that could be linked and
communicate with each other gave rise to distributed computing. Distributed computations are carried out on
more than one machine. When computers in a group work in cooperation, they make a distributed system.Ex-
NFS-Andrew,Amoeba

Sarvesh Kr. Soni (Asst. Prof., Dept. of IT) 8


Difference between Linux and Windows OS:

S. no. Point Linux Windows


Open-Source & Proprietary & Licensed
1 Type
FreeWare:
Linus Torvalds(1991), MS-Win3.1(1992)
Inventor(year)
2
3 Application Less More
4 Cost Freely available Costly
High Security:It never Low security:
5 Security
creates Registry Keys
boot from either primary Must boot from primary
6 Booting
or logical partition. partition.
File names-case File names- not case
7. Case sensitivity
sensitive sensitive
More Reliable: has Less Reliable
8. Reliability
better backup concept
Less Popular More Popular(Due to Its
9. Popularity
better GUI support)

Programming Languages classification


Examples
Algorithmic--- Fortran, COBOL,C
Procedural Object-oriented--C++, JAVA,C#
Scripting ------ VB, PERL, JavaScript
Functional ---- LISP, ML
High Level non-procedural
Logical ------- PROLOG
Numerical ---- MatLab
Problem-oriented Symbolic ----- Mathematica
Publishing ---- Latex

Programming Lang.

Low level Assembly Language (Machine dependent)

 A typical programming task can be divided into two phases:


• Problem solving phase
– produce an ordered sequence of steps that describe solution of problem
– this sequence of steps is called an algorithm
• Implementation phase
– implement the program in some programming language

Sarvesh Kr. Soni (Asst. Prof., Dept. of IT) 9


Algorithm: The Fundamental knowledge needed to solve problems using a computer is the notion of an algorithm.
“An Algorithm is a precise specification of a sequence of instructions (tells what task is to be executed) to
be carried out in order solve a given problem”.

Features of a good algorithm:


1. Finiteness: An algorithm must terminate after a finite number of steps and further each step must be
executable in finite amount of time
2. Definiteness (no ambiguity): Each steps of an algorithm must be precisely defined; the action to be
carried out must be rigorously and unambiguously specified for each case.
3. Inputs/ Output: An algorithm has zero or more (but only finite), number of inputs and (atleast
1)output.
4. Effectiveness(efficient): An algorithm should be effective. This means that each of the operation to
be performed in an algorithm must be sufficiently basic that it can be done exactly and in a finite
length of time.

FLOWCHARTS

• Flowchart is developed for showing the steps involved in a process(algorithm).


• A flowchart is a diagram made up of boxes, diamonds and other shapes, connected by arrows.
• Flowchart combines symbols and flow lines, to show the operation of an algorithm in a figure.

Flow chart Symbols

Sarvesh Kr. Soni (Asst. Prof., Dept. of IT) 10


start
i) Swapping of given two numbers without using third variable.
ALGORITHM:
take a,b
Step1: Start
Step2: Input a,b
a=1,b=10
Step3: Set a=a+b
Step4: Set b=a-b
a=a+b;b=a-b;a=a-b
Step 5: Set a=a-b
Step6: Print the result a,b
Display a and b
Step7: Stop

stop

ii) Convert temperature from centigrade to Fahrenheit.

Algorithm:

Step 1 : start
Setp 2 : read temperature in centrigrade Start
Step 3 : caluculate Fahrenheit = 32 + (centigrade * (1.8));
Step 4 : display centigrade and Fahrenheit
Step 5 : stop
Read cent
Flow chart

Fah = 32+(cent*1,8)

Display cent, fah

End

iii) WAP to find area and circumference of circle with radius r.

Algorithm:
1.Start
2. Read the value of radius r of Circle
3. Give Pi = 3.14
4. Calculate area of Circle A= Pi x r x r
5. Calculate Circumference of circle
C= 2 X Pi X r
5. Print area =A and Circumference =C
6.End.

Sarvesh Kr. Soni (Asst. Prof., Dept. of IT) 11


Start

iv) Write a program to find greatest among three numbers Take a,b,c
ALGORITHM:
Step1:start If
Step2:input a,b,c (a>b)&&(a
>c)
Step3:if(a>b) &&(a>c) Display a

Step4:display a is grater
Step 5:else
Step6:if(b>c) If (b>c)

Step7: display b is grater


Step 8:else Display b
Display c
Step: display c is grater
Step10:stop
FLOWCHART:
Stop
To find greatest among 3 numbers

v) Write a program to find total of first n natural numbers

Algorithm: start

Step1: start
Step2: read n Read n
Step3: i=0,sum=0
Step4: perform from step 5 to step 6 until i<=n
Step5: i++
i=0;sum=0
Step6:sum+=i;
Step7: write sum
Step8: stop
While(i<=n)

Flow chart:
I=i+1

Sum+=i

Write sum

stop

vi) Write a program to find the factorial of a given number.


ALGORITHM:
Sarvesh Kr. Soni (Asst. Prof., Dept. of IT) 12
Step1: start
Take n
Step2: input n,I,f
Step3: f=i=1
F=i=1
Step4: if(i<=n)
Step5: f=f*i
Step6: i=i+1 If
(i<=n)
Step7: repeat from step5 to step6 till steps true
Step8: print f
tep9: stop
FLOWCHART:
f=f*i; i=i+1
Program to find the factorial of a given number
Display f

Stop

Structured programming
Structured programming, sometimes known as modular programming.

It is a subset of procedural programming that enforces a logical structure on the program being written to make it
more efficient and easier to understand and modify.

It is A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having
a single entry and a single exit point.

In Struct.Prog., control is passed downward through the structure without unconditional branches to higher levels of
the structure.

Three types of control flow are used:


• Sequential,
• Conditional (test)
• Iteration (repeating).
Structured programming frequently employs a top-down design model, in which developers map out the overall
program structure into separate subsections.

A defined function or set of similar functions is coded in a separate module or sub module, which means that the
code can be loaded in to memory more efficiently and that modules can be reused in other programs.
After a module has been tested individually, it is then integrated with other modules into the overall program structure.

Top down approach and Stepwise refinement


With the top-down approach, we start with our top-level program, then divide and further sub-divide it into many
different modules. The division process is known as stepwise refinement.
As we design each module, we will discover what kind of sub modules

Sarvesh Kr. Soni (Asst. Prof., Dept. of IT) 13


we will need, and then continue to program those.
After programming our smaller sub modules, we will group them together into the larger module.

• The key to stepwise refinement is that each module should


end up doing only one task.
• One advantage of the top-down approach is that we see the
full picture at first.
• Therefore, the top-down approach is suitable for larger
problems.

Sarvesh Kr. Soni (Asst. Prof., Dept. of IT) 14

You might also like