SlideShare uma empresa Scribd logo
1 de 14
Baixar para ler offline
GITAM UNIVERSITY
(Declared as Deemed to be University U/S 3 of UGC Act, 1956)
Lecture Notes
of
Programming with C
[ERUCS 105]
INTRODUCTION
Lecture-1
Hyderabad Campus, Rudraram
HYDERABAD-502329
JULY-NOV 2013
CONTENTS LIST OF TABLES
Contents
1 Computers 3
1.1 Input Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Arithmetic Logic Unit(ALU) . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Control Unit(CU) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Memory Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 Output Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.6 Classification of computer software . . . . . . . . . . . . . . . . . . . . . 5
2 Classification of Computers 6
3 Generation of Programming Languages 7
3.1 First Generation: Machine Language . . . . . . . . . . . . . . . . . . . . 7
3.2 Second Generation: Assembly Language . . . . . . . . . . . . . . . . . . 7
3.3 3GL: HLL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.4 4GL: Very High Level Languages . . . . . . . . . . . . . . . . . . . . . . 8
4 Sample Programs 9
4.1 The While Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5 Review Questions 13
5.1 Long answer Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.2 Short answer Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
6 Snippet Programs 14
List of Figures
1 Parts of Computer System . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Hardware blocks of a computer . . . . . . . . . . . . . . . . . . . . . . . 4
3 Relationship between hardware and software . . . . . . . . . . . . . . . . 5
4 While Loop syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
5 While Loop Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
List of Tables
1 Generations of Computer . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2
1 COMPUTERS
1
1 Computers
The Computer is a programmable finite state machine which can perform precise
arithmetic and logic operations.
A programmable finite state machine is one that can take one of a fixed range
of values. The computer is said to be programmable because it can instructed to
perform tasks within it’s capacity.
When we talk about a computer, we actually mean two things
 First is the computer hardware that does all the physical work computers are known
for.
 Second is the computer software that commands the hardware what to do and how
to do it.
A list of instructions can be submitted to the computer in the form of a program.
Figure 1: Parts of Computer System
a task is performed by executing the corresponding program. A collection of related
programs is referred to as the software. The physical circuitry and components are
known as the hardware. Hardware can be categorized into five blocks.
They are:
• Input Unit
• Arithmetic logic Unit(ALU)
• Control Unit(CU)
• Memory Unit
• Output Unit
1.1 Input Unit
The input unit is the device used to enter data and instructions into the computer. The
data read from the input device is stored in the computer’s memory.
Some common input devices are: Keyboard, mouse, joystick, light pen, etc.
1
PROGRAMMING with C[ERUCS 105]
3
1.2 Arithmetic Logic Unit(ALU) 1 COMPUTERS
2
1.2 Arithmetic Logic Unit(ALU)
The ALU performs arithmetic and logic operations. The arithmetic operations include
addition, subtraction, multiplication and division.
Figure 2: Hardware blocks of a computer
1.3 Control Unit(CU)
The control unit coordinates the activities of the various components of a computer.
The arithmetic logic unit and the control unit together comprise the Central processing
Unit(CPU). The CPUs are called Microprocessor. The speed of a computer depends
on the clock frequency of the microprocessor.
Some popular microprocessors are: Intel, Pentium, Pentium Pro, IBM, AMD, etc.
1.4 Memory Unit
The information(instructions and data) required is stored is stored in memory. The
computer memory is constructed out of semi-conducting material and stores information
in binary form. Binary information is composed of two symbols o and 1, called binary
digits(bits). All information within the computer is represented by two digits. The
memory is organized into equal sized units(usually a collection of 8 bits, called byte).
These units are arranged in a sequence and are identified by numbers called addresses.
The memory of a computer can be divided into distinct parts. They are:
• Registers
• Internal Cacahe
• External Cache
• Main memory
• Secondary memory
2
PROGRAMMING with C[ERUCS 105]
4
1.5 Output Unit 1 COMPUTERS
3
1.5 Output Unit
Just s input devices are used to supply the computer with data, there should be some
means for the computer to communicate with the user. The information generated by
the computer is displayed using an output device.
Some examples of output devices are: Cathod Ray Tube(CRT), Printer, Card
punch, plotters, etc.
1.6 Classification of computer software
Computer software can be brodely classified into two groups: System software and
application software.
• System software provides a general programming environment in which programmers
can create specific applications to suite their needs. This environment provides new
functions that are not available at the hardware level and performs tasks related to
executing the application program.
• Application software is designed to solve a particular problem for users. It is generally
what we think of when we say the word computer programs.
Examples of application software include spreadsheets, database systems, desktop
publishing systems, program development software, etc.
Figure 3: Relationship between hardware and software
3
PROGRAMMING with C[ERUCS 105]
5
2 CLASSIFICATION OF COMPUTERS
4
2 Classification of Computers
 The Abacus was invented around 2500 BC. It is a device made of beads strung on
rods and used to perform simple computations.
 Napier invented a device for computing logarithms of natural numbers. It was called
Napier’s Bones and enabled multiplication to be done easily.
 Blaise Pascal invented the addressing machine in 1642 AD.
 charless Babbage designed the difference engine in 1822 AD and analytical engine
in 1833 AD.
Computers can be classified into five generations, based on the technology and performance
and is shown in Table 1.
Table 1: Generations of Computer
Generation Year Hardware Software Performance
Zero Pre 1946 Counter wheels
with mechanical
components
− − −− Numerical op-
erations at slow
speed
First 1946-1956 Vacuum Tubes Stored Pro-
grams, Machine
Code, Symbolic
code
2 KB Memory, 10
Kilo instructions
per second
Second 1956-1963 Transistors High Level Lan-
guage(HLL),
FORTRAN,
ALGOL, etc
32 KB Memory,
200 Kilo instruc-
tions per second
Third 1964-1981 ICs, Semi-
Conductor
memory
PASCAL, C, etc 2 MB Memory,
5 Million In-
structions Per
Second(MIPS)
Fourth 1982-1989 VLSI OOPs Lan-
guages: C++,
etc
32 KB Memory,
30 Million In-
structions Per
Second(MIPS)
Fifth 1990-
NOW
Parallel Process-
ing
JAVA, .NET, etc 1 Giga to 1 Tera in-
structions per sec-
ond
4
PROGRAMMING with C[ERUCS 105]
6
3 GENERATION OF PROGRAMMING LANGUAGES
5
3 Generation of Programming Languages
A Programming language is a language specially designed to express computations
that can be performed by the computer. programming languages are used to create
programs that control the behaviour of a system, to express algorithms, or as a mode of
human-computer communication.
We now know that programming languages are the primary tools for creating software.
As of now hundreds of programming languages exits in the market, some more used than
others, and each claiming to be the best. However, back in 1940s when computers were
being developed there was just one language-the machine language.
The concept of generations of programming languages (also known as levels), is closely
connected to the advances, in technology that brought about computer generations. The
four generations of programming languages include:
• Machine language
• Assembly language
• High level Languages(HLL) (also known as third generation languages or 3GL)
• very High level Languages(HLL) (also known as fourth Generation Languages or 4GL)
3.1 First Generation: Machine Language
Machine language was used to program the first stored program on computer system.
This is the lowest level of programming language. The machine language is the only lan-
guage that the computer understands. All the commands and data values are expressed
using 1 and 0s, corresponding to the ’on’ and ’off’ electrical states in a computer.
The main advantage of machine language is that the code can run very fast and effi-
ciently, since it is directly executed by CPU. However, on the down side, the machine
language is difficult to learn and is far more difficult to edit if errors occur. Moreover, if
you want to add some instructions into memory at some location, then all the instruc-
tions after the insertion point would have to be moved down to make room in memory
to accommodate the new instructions.
3.2 Second Generation: Assembly Language
The second generation of programming language includes the assembly language. As-
sembly languages are symbolic programming languages that use symbolic notation to
represent machine-language instructions. These languages are closely connected to ma-
chine language and the internal architecture of the computer system on which they are
used. Since they are close to the machine, assembly language is also called low-level
language. Assembly language developed in the mid 1950s was a great leap forward. It
used symbolic codes also known as mnemonic codes that are easy-to-remember abbre-
viations, rather than numbers, Examples of these code include ADD for add, CMP for
compare, MUL for multiply, etc.
5
PROGRAMMING with C[ERUCS 105]
7
3.3 3GL: HLL 3 GENERATION OF PROGRAMMING LANGUAGES
6
3.3 3GL: HLL
A third generation programming language(3GL) is a refinement of the second generation
programming language. The 2GL languages brought logical structure to the software.
The third generation language was introduced to make the languages more programmer
friendly.
Generally, a statement written in high-level programming language will expand into sev-
eral machine language instructions. This is in contrast to assembly languages, where one
statement would generate one machine language instruction. 3GLs made programming
easier, efficient, and less prone to error.
3GL make it easier to write and debug a program and gives the programmer more time
to think about its overall logic. The programs written in such languages are portable
between machines.

Mais conteúdo relacionado

Mais procurados

Processor architecture
Processor architectureProcessor architecture
Processor architecture
Muuluu
 
basic structure of computers
basic structure of computersbasic structure of computers
basic structure of computers
Himanshu Chawla
 
Computer architecture
Computer architectureComputer architecture
Computer architecture
neclinux
 
Three Central Processing Unit
Three   Central Processing UnitThree   Central Processing Unit
Three Central Processing Unit
MISY
 
The Role Of The Cpu
The Role Of The CpuThe Role Of The Cpu
The Role Of The Cpu
gavhays
 
comp. org Chapter 1
comp. org Chapter 1comp. org Chapter 1
comp. org Chapter 1
Rajat Sharma
 
How does data flow around a computer system p3 1
How does data flow around a computer system p3 1How does data flow around a computer system p3 1
How does data flow around a computer system p3 1
lukecisco1
 
Computer system architecture
Computer system architectureComputer system architecture
Computer system architecture
Kumar
 
Co question bank LAKSHMAIAH
Co question bank LAKSHMAIAH Co question bank LAKSHMAIAH
Co question bank LAKSHMAIAH
veena babu
 

Mais procurados (20)

module 1 computer architecture diploma
 module 1 computer architecture diploma   module 1 computer architecture diploma
module 1 computer architecture diploma
 
Processor architecture
Processor architectureProcessor architecture
Processor architecture
 
Basic computer system
Basic computer systemBasic computer system
Basic computer system
 
computer Architecture
computer Architecturecomputer Architecture
computer Architecture
 
Computer architecture and organization
Computer architecture and organizationComputer architecture and organization
Computer architecture and organization
 
basic structure of computers
basic structure of computersbasic structure of computers
basic structure of computers
 
Basic structure of computers by aniket bhute
Basic structure of computers by aniket bhuteBasic structure of computers by aniket bhute
Basic structure of computers by aniket bhute
 
Unit 6
Unit 6Unit 6
Unit 6
 
Input-Output Modules
Input-Output ModulesInput-Output Modules
Input-Output Modules
 
Computer architecture
Computer architectureComputer architecture
Computer architecture
 
Three Central Processing Unit
Three   Central Processing UnitThree   Central Processing Unit
Three Central Processing Unit
 
The Role Of The Cpu
The Role Of The CpuThe Role Of The Cpu
The Role Of The Cpu
 
comp. org Chapter 1
comp. org Chapter 1comp. org Chapter 1
comp. org Chapter 1
 
Pipelining and vector processing
Pipelining and vector processingPipelining and vector processing
Pipelining and vector processing
 
Cpu organisation
Cpu organisationCpu organisation
Cpu organisation
 
How does data flow around a computer system p3 1
How does data flow around a computer system p3 1How does data flow around a computer system p3 1
How does data flow around a computer system p3 1
 
Computer system architecture
Computer system architectureComputer system architecture
Computer system architecture
 
Co notes3 sem
Co notes3 semCo notes3 sem
Co notes3 sem
 
Co question bank LAKSHMAIAH
Co question bank LAKSHMAIAH Co question bank LAKSHMAIAH
Co question bank LAKSHMAIAH
 
Overview of Computer Architecture and Organization
Overview of Computer Architecture and OrganizationOverview of Computer Architecture and Organization
Overview of Computer Architecture and Organization
 

Destaque

Switch case and looping statement
Switch case and looping statementSwitch case and looping statement
Switch case and looping statement
_jenica
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
Suneel Dogra
 
C Prog. - Decision & Loop Controls
C Prog. - Decision & Loop ControlsC Prog. - Decision & Loop Controls
C Prog. - Decision & Loop Controls
vinay arora
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
Jeya Lakshmi
 

Destaque (20)

C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
C Lecture
C LectureC Lecture
C Lecture
 
C
CC
C
 
Switch case and looping statement
Switch case and looping statementSwitch case and looping statement
Switch case and looping statement
 
Break and continue
Break and continueBreak and continue
Break and continue
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
 
Selection statements
Selection statementsSelection statements
Selection statements
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
Break and continue statement in C
Break and continue statement in CBreak and continue statement in C
Break and continue statement in C
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Ch3 selection
Ch3 selectionCh3 selection
Ch3 selection
 
C Prog. - Decision & Loop Controls
C Prog. - Decision & Loop ControlsC Prog. - Decision & Loop Controls
C Prog. - Decision & Loop Controls
 
Loops
LoopsLoops
Loops
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Loops Basics
Loops BasicsLoops Basics
Loops Basics
 
Loops
LoopsLoops
Loops
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 

Semelhante a Lecture 1

Ise iv-computer organization [10 cs46]-notes new
Ise iv-computer  organization [10 cs46]-notes newIse iv-computer  organization [10 cs46]-notes new
Ise iv-computer organization [10 cs46]-notes new
dilshad begum
 
COA-Unit-1-Basics.ppt
COA-Unit-1-Basics.pptCOA-Unit-1-Basics.ppt
COA-Unit-1-Basics.ppt
Ruhul Amin
 
Computer basics and i.o devices
Computer basics and i.o devicesComputer basics and i.o devices
Computer basics and i.o devices
kitturashmikittu
 
introduction to computers
 introduction to computers introduction to computers
introduction to computers
Deepak John
 

Semelhante a Lecture 1 (20)

Ise iv-computer organization [10 cs46]-notes new
Ise iv-computer  organization [10 cs46]-notes newIse iv-computer  organization [10 cs46]-notes new
Ise iv-computer organization [10 cs46]-notes new
 
C with lab
C with labC with lab
C with lab
 
Components of Computer system.ppt
Components of Computer system.pptComponents of Computer system.ppt
Components of Computer system.ppt
 
Fundamentals of Computers & Information System
Fundamentals of Computers & Information System  Fundamentals of Computers & Information System
Fundamentals of Computers & Information System
 
CSC204PPTNOTES
CSC204PPTNOTESCSC204PPTNOTES
CSC204PPTNOTES
 
introdection BASIC OF COMPUTER EDUCATION
introdection BASIC OF COMPUTER EDUCATIONintrodection BASIC OF COMPUTER EDUCATION
introdection BASIC OF COMPUTER EDUCATION
 
3945319.ppt
3945319.ppt3945319.ppt
3945319.ppt
 
COA-Unit-1-Basics.ppt
COA-Unit-1-Basics.pptCOA-Unit-1-Basics.ppt
COA-Unit-1-Basics.ppt
 
unit-i.pdf
unit-i.pdfunit-i.pdf
unit-i.pdf
 
Bt0062
Bt0062Bt0062
Bt0062
 
B T0062
B T0062B T0062
B T0062
 
Report windows 8.1 presentation
Report windows 8.1 presentationReport windows 8.1 presentation
Report windows 8.1 presentation
 
3945319.ppt
3945319.ppt3945319.ppt
3945319.ppt
 
Computer basics and i.o devices
Computer basics and i.o devicesComputer basics and i.o devices
Computer basics and i.o devices
 
CIS99_Ch_01 (1).pptx
CIS99_Ch_01 (1).pptxCIS99_Ch_01 (1).pptx
CIS99_Ch_01 (1).pptx
 
Pankaj kumar
Pankaj kumar Pankaj kumar
Pankaj kumar
 
introduction to computers
 introduction to computers introduction to computers
introduction to computers
 
Lesson 1 anatomy of a digital computer (230 kb)
Lesson 1  anatomy of a digital computer (230 kb)Lesson 1  anatomy of a digital computer (230 kb)
Lesson 1 anatomy of a digital computer (230 kb)
 
introduction to computer ppt [Autosaved].ppt
introduction to computer ppt [Autosaved].pptintroduction to computer ppt [Autosaved].ppt
introduction to computer ppt [Autosaved].ppt
 
janvichauhan110cs.pptx
janvichauhan110cs.pptxjanvichauhan110cs.pptx
janvichauhan110cs.pptx
 

Último

Último (20)

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Lecture 1

  • 1. GITAM UNIVERSITY (Declared as Deemed to be University U/S 3 of UGC Act, 1956) Lecture Notes of Programming with C [ERUCS 105] INTRODUCTION Lecture-1 Hyderabad Campus, Rudraram HYDERABAD-502329 JULY-NOV 2013
  • 2. CONTENTS LIST OF TABLES Contents 1 Computers 3 1.1 Input Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.2 Arithmetic Logic Unit(ALU) . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.3 Control Unit(CU) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.4 Memory Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.5 Output Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.6 Classification of computer software . . . . . . . . . . . . . . . . . . . . . 5 2 Classification of Computers 6 3 Generation of Programming Languages 7 3.1 First Generation: Machine Language . . . . . . . . . . . . . . . . . . . . 7 3.2 Second Generation: Assembly Language . . . . . . . . . . . . . . . . . . 7 3.3 3GL: HLL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.4 4GL: Very High Level Languages . . . . . . . . . . . . . . . . . . . . . . 8 4 Sample Programs 9 4.1 The While Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5 Review Questions 13 5.1 Long answer Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.2 Short answer Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 6 Snippet Programs 14 List of Figures 1 Parts of Computer System . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2 Hardware blocks of a computer . . . . . . . . . . . . . . . . . . . . . . . 4 3 Relationship between hardware and software . . . . . . . . . . . . . . . . 5 4 While Loop syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 5 While Loop Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 List of Tables 1 Generations of Computer . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2
  • 3. 1 COMPUTERS 1 1 Computers The Computer is a programmable finite state machine which can perform precise arithmetic and logic operations.
  • 4. A programmable finite state machine is one that can take one of a fixed range of values. The computer is said to be programmable because it can instructed to perform tasks within it’s capacity. When we talk about a computer, we actually mean two things First is the computer hardware that does all the physical work computers are known for. Second is the computer software that commands the hardware what to do and how to do it. A list of instructions can be submitted to the computer in the form of a program. Figure 1: Parts of Computer System a task is performed by executing the corresponding program. A collection of related programs is referred to as the software. The physical circuitry and components are known as the hardware. Hardware can be categorized into five blocks. They are: • Input Unit • Arithmetic logic Unit(ALU) • Control Unit(CU) • Memory Unit • Output Unit 1.1 Input Unit The input unit is the device used to enter data and instructions into the computer. The data read from the input device is stored in the computer’s memory.
  • 5. Some common input devices are: Keyboard, mouse, joystick, light pen, etc. 1 PROGRAMMING with C[ERUCS 105] 3
  • 6. 1.2 Arithmetic Logic Unit(ALU) 1 COMPUTERS 2 1.2 Arithmetic Logic Unit(ALU) The ALU performs arithmetic and logic operations. The arithmetic operations include addition, subtraction, multiplication and division. Figure 2: Hardware blocks of a computer 1.3 Control Unit(CU) The control unit coordinates the activities of the various components of a computer. The arithmetic logic unit and the control unit together comprise the Central processing Unit(CPU). The CPUs are called Microprocessor. The speed of a computer depends on the clock frequency of the microprocessor.
  • 7. Some popular microprocessors are: Intel, Pentium, Pentium Pro, IBM, AMD, etc. 1.4 Memory Unit The information(instructions and data) required is stored is stored in memory. The computer memory is constructed out of semi-conducting material and stores information in binary form. Binary information is composed of two symbols o and 1, called binary digits(bits). All information within the computer is represented by two digits. The memory is organized into equal sized units(usually a collection of 8 bits, called byte). These units are arranged in a sequence and are identified by numbers called addresses.
  • 8. The memory of a computer can be divided into distinct parts. They are: • Registers • Internal Cacahe • External Cache • Main memory • Secondary memory 2 PROGRAMMING with C[ERUCS 105] 4
  • 9. 1.5 Output Unit 1 COMPUTERS 3 1.5 Output Unit Just s input devices are used to supply the computer with data, there should be some means for the computer to communicate with the user. The information generated by the computer is displayed using an output device.
  • 10. Some examples of output devices are: Cathod Ray Tube(CRT), Printer, Card punch, plotters, etc. 1.6 Classification of computer software Computer software can be brodely classified into two groups: System software and application software. • System software provides a general programming environment in which programmers can create specific applications to suite their needs. This environment provides new functions that are not available at the hardware level and performs tasks related to executing the application program. • Application software is designed to solve a particular problem for users. It is generally what we think of when we say the word computer programs.
  • 11. Examples of application software include spreadsheets, database systems, desktop publishing systems, program development software, etc. Figure 3: Relationship between hardware and software 3 PROGRAMMING with C[ERUCS 105] 5
  • 12. 2 CLASSIFICATION OF COMPUTERS 4 2 Classification of Computers The Abacus was invented around 2500 BC. It is a device made of beads strung on rods and used to perform simple computations. Napier invented a device for computing logarithms of natural numbers. It was called Napier’s Bones and enabled multiplication to be done easily. Blaise Pascal invented the addressing machine in 1642 AD. charless Babbage designed the difference engine in 1822 AD and analytical engine in 1833 AD. Computers can be classified into five generations, based on the technology and performance and is shown in Table 1. Table 1: Generations of Computer Generation Year Hardware Software Performance Zero Pre 1946 Counter wheels with mechanical components − − −− Numerical op- erations at slow speed First 1946-1956 Vacuum Tubes Stored Pro- grams, Machine Code, Symbolic code 2 KB Memory, 10 Kilo instructions per second Second 1956-1963 Transistors High Level Lan- guage(HLL), FORTRAN, ALGOL, etc 32 KB Memory, 200 Kilo instruc- tions per second Third 1964-1981 ICs, Semi- Conductor memory PASCAL, C, etc 2 MB Memory, 5 Million In- structions Per Second(MIPS) Fourth 1982-1989 VLSI OOPs Lan- guages: C++, etc 32 KB Memory, 30 Million In- structions Per Second(MIPS) Fifth 1990- NOW Parallel Process- ing JAVA, .NET, etc 1 Giga to 1 Tera in- structions per sec- ond 4 PROGRAMMING with C[ERUCS 105] 6
  • 13. 3 GENERATION OF PROGRAMMING LANGUAGES 5 3 Generation of Programming Languages A Programming language is a language specially designed to express computations that can be performed by the computer. programming languages are used to create programs that control the behaviour of a system, to express algorithms, or as a mode of human-computer communication. We now know that programming languages are the primary tools for creating software. As of now hundreds of programming languages exits in the market, some more used than others, and each claiming to be the best. However, back in 1940s when computers were being developed there was just one language-the machine language. The concept of generations of programming languages (also known as levels), is closely connected to the advances, in technology that brought about computer generations. The four generations of programming languages include: • Machine language • Assembly language • High level Languages(HLL) (also known as third generation languages or 3GL) • very High level Languages(HLL) (also known as fourth Generation Languages or 4GL) 3.1 First Generation: Machine Language Machine language was used to program the first stored program on computer system. This is the lowest level of programming language. The machine language is the only lan- guage that the computer understands. All the commands and data values are expressed using 1 and 0s, corresponding to the ’on’ and ’off’ electrical states in a computer. The main advantage of machine language is that the code can run very fast and effi- ciently, since it is directly executed by CPU. However, on the down side, the machine language is difficult to learn and is far more difficult to edit if errors occur. Moreover, if you want to add some instructions into memory at some location, then all the instruc- tions after the insertion point would have to be moved down to make room in memory to accommodate the new instructions. 3.2 Second Generation: Assembly Language The second generation of programming language includes the assembly language. As- sembly languages are symbolic programming languages that use symbolic notation to represent machine-language instructions. These languages are closely connected to ma- chine language and the internal architecture of the computer system on which they are used. Since they are close to the machine, assembly language is also called low-level language. Assembly language developed in the mid 1950s was a great leap forward. It used symbolic codes also known as mnemonic codes that are easy-to-remember abbre- viations, rather than numbers, Examples of these code include ADD for add, CMP for compare, MUL for multiply, etc. 5 PROGRAMMING with C[ERUCS 105] 7
  • 14. 3.3 3GL: HLL 3 GENERATION OF PROGRAMMING LANGUAGES 6 3.3 3GL: HLL A third generation programming language(3GL) is a refinement of the second generation programming language. The 2GL languages brought logical structure to the software. The third generation language was introduced to make the languages more programmer friendly. Generally, a statement written in high-level programming language will expand into sev- eral machine language instructions. This is in contrast to assembly languages, where one statement would generate one machine language instruction. 3GLs made programming easier, efficient, and less prone to error. 3GL make it easier to write and debug a program and gives the programmer more time to think about its overall logic. The programs written in such languages are portable between machines.
  • 15. A program written in standard C can be compiled and executed on any computer that has a standard C compiler. 3.4 4GL: Very High Level Languages with the generation, programming languages started becoming easier to use and more like natural languages. However, 4GLs is a little different from its prior generation because they are basically non-procedural. When writing code using a procedural language, programmer has to tell the computer how a task is done – add this, compare that, do this if the condition is true, and so on, in a very specific step-by-step manner.
  • 16. A typical example of a 4GL is the query language that allows a user to request information from a database with precisely worded English-like sentences. 6 PROGRAMMING with C[ERUCS 105] 8
  • 17. 4 SAMPLE PROGRAMS 7 4 Sample Programs 4.1 The While Loop • In ’C’ programming that user want to do something a fixed number of times. • The while loop is ideally suited for such cases. The while loop is suited for following cases. CASE-1: • If you want to calculate gross salaries of ten different persons. CASE-2: • If you you want to convert temperatures from centigrade to fahrenheit for 15 different cities. Example: 1 /∗ Calculation of simple i n t e r e s t for 3 s e t s of p , n and r ∗/ 2 #includestdio . h 3 main( ) 4 { 5 int p , n , count ; 6 float r , s i ; 7 count = 1; 8 while ( count = 3 ) 9 { 10 p r i n t f ( ” Enter values of p , n and r ” ) ; 11 scanf ( ”%d %d %f ” , p , n , r ) ; 12 s i=p∗n ∗ r / 100 ; 13 p r i n t f ( ”Simple i n t e r e s t = Rs . %f ” , s i ) ; 14 count=count+1; 15 } 16 } example1.c Sample Output: Enter values of p, n and r 1000 5 13.5 Simple interest = Rs. 675.000000 Enter values of p, n and r 2000 5 13.5 Simple interest = Rs. 1350.000000 Enter values of p, n and r 3500 5 13.5 Simple interest = Rs. 2362.500000 7 PROGRAMMING with C[ERUCS 105] 9
  • 18. 4.1 The While Loop 4 SAMPLE PROGRAMS 8 Analysis: • The program executes all statements after the while 3 times. • The logic for calculating the simple interest is written within a pair of braces immediately after the while keyword. • These statements form what is called the body of the while loop. • The parentheses after the while contain a condition. So long as this condition remains true all statements within the body of the while loop keep getting executed repeatedly. • To begin with the variable count is initialized to 1 and every time the simple interest logic is executed the value of count is incremented by one. • The variable count is many a times called either a loop counter or an index variable. Syntax initialise loop counter ; while ( test loop counter using a condition ) { do this(Statement-1) ; and this(statement-2) ; increment loop counter ; } Figure 4: While Loop syntax 8 PROGRAMMING with C[ERUCS 105] 10
  • 19. 4.1 The While Loop 4 SAMPLE PROGRAMS 9 Figure 5: While Loop Flowchart Note-I The statements within the while loop would keep on getting executed till the condi- tion being tested remains true. When the condition becomes false, the control passes to the first statement that follows the body of the while loop. Note-II The condition being tested may use relational or logical operators as shown in the following examples: while ( i = 10 ) while ( i = 10 j = 15 ) Note-III The statements within the loop may be asingle line (or) a block of statements. Examples: while ( i = 10 ) i=i+1; is same as while ( i = 10 ) { i=i+1; } 9 PROGRAMMING with C[ERUCS 105] 11
  • 20. 4.1 The While Loop 4 SAMPLE PROGRAMS 10 Note-IV As a rule while must test a condition that will eventually become false. Otherwise the loop would be executed forever, indefinitly. main() { int i=1; while ( i = 10 ) printf(”%d”,i); } The correct form would be as under main() { int i=1; while ( i = 10 ) { printf(”%d”,i); i=i+1; } } Note-IV Instead of incrementing a loop counter, We can even decrement it and still manage to get the body of the loop executed repeatedly. This is shown below: main( ) { int i = 5 ; while (i = 1 ) { printf (”Make the computer literate” ) ; i = i - 1 ; } } Note-V It is not necessary that a loop counter must only be an int. It can even be a float. main( ) { float a = 10.0 ; while (a = 10.5 ) { printf ( ” addition”); a = a + 0.1 ; } } 10 PROGRAMMING with C[ERUCS 105] 12
  • 21. 5 REVIEW QUESTIONS 11 5 Review Questions 5.1 Long answer Questions
  • 22. Differentiate between computer hardware and software?
  • 23. Explain the role of Operating System?
  • 24. Write a short notes on computer?
  • 25. What are the steps involved in algorithm design?
  • 26. What are the popular features of C language? 5.2 Short answer Questions
  • 27. What is system software?
  • 28. What is a program?
  • 31. What is a micro processor? 11 PROGRAMMING with C[ERUCS 105] 13
  • 32. 6 SNIPPET PROGRAMS 12 6 Snippet Programs What would be the output of the following programs (a) main( ) { void slogan( ) ; int c = 5 ; c = slogan( ) ; printf ( ”% d”, c ) ; } void slogan( ) { printf ( ”Only He men use C!” ) ; } (b) main( ) { void slogan( ) ; int c = 5 ; c = slogan( ) ; printf ( ”% d”, c ) ; } void slogan( ) { printf ( ”Only He men use C!” ) ; } (c) main( ) { void slogan( ) ; int c = 5 ; c = slogan( ) ; printf ( ”% d”, c ) ; } void slogan( ) { printf ( ”Only He men use C!” ) ; } 12 PROGRAMMING with C[ERUCS 105] 14