SlideShare a Scribd company logo
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.

More Related Content

PDF
Computer Organization and Architecture 10th Edition by Stallings Test Bank
PDF
Computer Organization (Unit-1)
PDF
Computer organization-and-architecture-questions-and-answers
PPT
Unit 1 basic structure of computers
PPT
HARDWARE
PDF
Computer Fundamentals_Chapter 02 bco
PPT
Basic structure of computers
PDF
VTU 4TH SEM CSE COMPUTER ORGANIZATION SOLVED PAPERS OF JUNE-2013 JUNE-2014 & ...
Computer Organization and Architecture 10th Edition by Stallings Test Bank
Computer Organization (Unit-1)
Computer organization-and-architecture-questions-and-answers
Unit 1 basic structure of computers
HARDWARE
Computer Fundamentals_Chapter 02 bco
Basic structure of computers
VTU 4TH SEM CSE COMPUTER ORGANIZATION SOLVED PAPERS OF JUNE-2013 JUNE-2014 & ...

What's hot (20)

DOC
module 1 computer architecture diploma
PDF
Processor architecture
PDF
Basic computer system
PPTX
computer Architecture
PPTX
Computer architecture and organization
PPT
basic structure of computers
PPT
Basic structure of computers by aniket bhute
PDF
Unit 6
PDF
Input-Output Modules
PDF
Computer architecture
PPT
Three Central Processing Unit
PPT
The Role Of The Cpu
PPT
comp. org Chapter 1
PPTX
Pipelining and vector processing
PPT
Cpu organisation
PPTX
How does data flow around a computer system p3 1
PPTX
Computer system architecture
DOCX
Co notes3 sem
PDF
Co question bank LAKSHMAIAH
PDF
Overview of Computer Architecture and Organization
module 1 computer architecture diploma
Processor architecture
Basic computer system
computer Architecture
Computer architecture and organization
basic structure of computers
Basic structure of computers by aniket bhute
Unit 6
Input-Output Modules
Computer architecture
Three Central Processing Unit
The Role Of The Cpu
comp. org Chapter 1
Pipelining and vector processing
Cpu organisation
How does data flow around a computer system p3 1
Computer system architecture
Co notes3 sem
Co question bank LAKSHMAIAH
Overview of Computer Architecture and Organization
Ad

Viewers also liked (20)

DOCX
C programming tutorial
PPT
C Lecture
PPTX
Switch case and looping statement
PPSX
Break and continue
PPSX
C lecture 3 control statements slideshare
PPTX
Selection statements
PPTX
Conditional Statement in C Language
PPSX
Break and continue statement in C
DOC
Jumping statements
PPSX
C lecture 4 nested loops and jumping statements slideshare
PPTX
C decision making and looping.
PPTX
Switch case and looping
PPT
Ch3 selection
PDF
C Prog. - Decision & Loop Controls
PPT
Ch3 repetition
PPTX
Loops Basics
PPTX
PPTX
Looping statements in C
C programming tutorial
C Lecture
Switch case and looping statement
Break and continue
C lecture 3 control statements slideshare
Selection statements
Conditional Statement in C Language
Break and continue statement in C
Jumping statements
C lecture 4 nested loops and jumping statements slideshare
C decision making and looping.
Switch case and looping
Ch3 selection
C Prog. - Decision & Loop Controls
Ch3 repetition
Loops Basics
Looping statements in C
Ad

Similar to Lecture 1 (20)

DOC
Ise iv-computer organization [10 cs46]-notes new
PDF
C with lab
PPT
Components of Computer system.ppt
PPTX
Fundamentals of Computers & Information System
PPTX
CSC204PPTNOTES
PPTX
introdection BASIC OF COMPUTER EDUCATION
PPTX
module1_CA_for use of tribal network .pptx
PPT
3945319.ppt
PPT
COA-Unit-1-Basics.ppt
PDF
unit-i.pdf
DOC
Bt0062
DOC
B T0062
PDF
Report windows 8.1 presentation
PPT
3945319.ppt
PPTX
DSE LECTURE 1 -LRW_ Introduction_to_Computer.pptx
PPT
Computer basics and i.o devices
PPTX
CIS99_Ch_01 (1).pptx
DOCX
Pankaj kumar
PDF
introduction to computers
PDF
Lesson 1 anatomy of a digital computer (230 kb)
Ise iv-computer organization [10 cs46]-notes new
C with lab
Components of Computer system.ppt
Fundamentals of Computers & Information System
CSC204PPTNOTES
introdection BASIC OF COMPUTER EDUCATION
module1_CA_for use of tribal network .pptx
3945319.ppt
COA-Unit-1-Basics.ppt
unit-i.pdf
Bt0062
B T0062
Report windows 8.1 presentation
3945319.ppt
DSE LECTURE 1 -LRW_ Introduction_to_Computer.pptx
Computer basics and i.o devices
CIS99_Ch_01 (1).pptx
Pankaj kumar
introduction to computers
Lesson 1 anatomy of a digital computer (230 kb)

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Machine Learning_overview_presentation.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PDF
Empathic Computing: Creating Shared Understanding
Cloud computing and distributed systems.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
A comparative analysis of optical character recognition models for extracting...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Building Integrated photovoltaic BIPV_UPV.pdf
Spectral efficient network and resource selection model in 5G networks
MIND Revenue Release Quarter 2 2025 Press Release
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation_ Review paper, used for researhc scholars
Digital-Transformation-Roadmap-for-Companies.pptx
Machine Learning_overview_presentation.pptx
The AUB Centre for AI in Media Proposal.docx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MYSQL Presentation for SQL database connectivity
Dropbox Q2 2025 Financial Results & Investor Presentation
Big Data Technologies - Introduction.pptx
Spectroscopy.pptx food analysis technology
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
Empathic Computing: Creating Shared Understanding

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