You are on page 1of 46

Unit I:

Problem Solving using Computers,


Overview of C Language
C Language Preliminaries
Presented by
Dr Raghu Indrakanti
Assistant Professor
Department of ECE
Problem Solving using Computers
• Introduction
• Algorithms
• Flowcharts and Pseudo code

Overview of C Language
• Introduction
UNIT I
• Salient Features of C Language
• Structure of a C Program

C Language Preliminaries
• Keywords and Identifiers
• Constants
• Variables
• Data Types
• Input-Output Statements with suitable illustrative C Programs
Introduction to Computer
▪ Computer is an advanced electronic device that takes raw data as input from the user and
processes these data under the control of set of instructions (called program) and gives the
result (output) and saves output for the future use.
▪ A computer is a combination of hardware and software resources which integrate together
and provides various functionalities to the user.
▪ Hardware are the physical components of a computer like the processor, memory devices,
monitor, keyboard etc. while software is the set of programs or instructions that are required
by the hardware resources to perform various operations as per the requirement of users.
Introduction to Computer
• Application areas may broadly be classifi ed into the following major categories.

1. Data processing (commercial use)


2. Numerical computing (scientific use)
3. Text (word) processing (office and educational use)
4. Message communication (e-mail)
5. Image processing (animation and industrial use)
6. Voice recognition (multimedia)
Types of Computers
Computers are classified into 4 categories.
1) Super Computers –
• Most powerful type of computer.
• High capacity computers used by very large organizations.
• For Ex. NASA uses supercomputer to track and control space explorations

2) Mainframe Computer –
• Are capable of great processing speed and data storage.

3) Mini Computer –
• Medium sized companies or departments of large companies use them for specific purposes.

4) Microcomputers:
• Desktop computer - small enough to fit on top of or along the size of desk.
• Notebook computers – are portable and fits into most briefcases.
• Personal digital assistant (PDA) – Also called palmtop or handheld computers.
Types of Computers
Computers are classified into 4 categories.
1) Super Computers –
• Most powerful type of computer.
• High capacity computers used by very large organizations.
• For Ex. NASA uses supercomputer to track and control space explorations
2) Mainframe Computer – Types of Computers
• Are not powerful as supercomputer.
• Are capable of great processing speed and data storage.
• For example insurance companies uses mainframes to process information about millions of
policyholders.
3) Mini Computer – Types of Computers
• Are desk-sized machines.
• Medium sized companies or departments of large companies use them for specific purposes.
Types of Computers
4) Microcomputers: Although least powerful, microcomputers are the most widely used and fastest growing
type of computer.
• Categories of microcomputer includes –
• Desktop computer - small enough to fit on top of or along the size of desk.
• Notebook computers – are portable and fits into most briefcases.
• Personal digital assistant (PDA) – Also called palmtop or handheld computers.
Microcomputers
A microcomputer is defined as a computer that has a microprocessor as its CPU. The
microcomputer system can perform the following basic operations:

• Input — It is the process of entering data and instructions into the microcomputer system.
• Storing — It is the process of saving data and instructions in the memory of the
microcomputer system, so that they can be use whenever required.
• Processing — It is the process of performing arithmetic or logical operations on data, where
data can be converted into useful information. Various arithmetic operations include addition,
subtraction, multiplication and division. Among logical operations, operations of
comparisons like equal to, less than, greater than, etc., are prominent in use.
• Output — It provides the results to the user, which could be in the form of visual display
and/or printed reports.
• Control— It helps in directing the sequence and manner in which all the above operations are
performed.
A COMPUTER SYSTEM
A computer system comprises of hardware and
software components. Hardware refers to the
physical parts of the computer system and
software is the set of instructions or programs
that are necessary for the functioning of a
computer to perform certain tasks.

• Input devices
• Processor
• Output devices
• Memory
INPUT DEVICES
Input devices can be connected to the computer system using cables. The most commonly used
input devices among others are:

• Keyboard • Scanner

• Mouse
PROCESSOR
• The CPU consists of Control Unit (CU) and ALU.
• CU stores the instruction set, which specifi es the operations to be performed by the computer.
• CU transfers the data and the instructions to the ALU for an arithmetic operation.
• ALU performs arithmetical or logical operations on the data received.
Motherboard
• It refers to a device used for connecting the CPU with the input and output devices.
• The components on the motherboard are connected to all parts of a computer and are kept
insulated from each other.
Random Access Memory (RAM): It refers to primary memory of a computer that stores information
and programs, until the computer is used.
• RAM is available as a chip that can be connected to the RAM slots in the motherboard.
Video Card/Sound card
OUTPUT DEVICES

• Monitor
• Printer

• Speaker • Plotter
MEMORY MANAGEMENT
• Primary Memory:

ROM — ROM represents Read Only Memory that stores data and instructions, even when
the computer is turned off. It is the permanent memory of the computer where the contents
cannot be modified by an end user. ROM is a chip that is inserted into the motherboard.
• Primary Memory: MEMORY MANAGEMENT
RAM — RAM is the read/write memory unit in which the information is retained only as
long as there is a regular power supply. When the power supply is interrupted or switched
off, the information stored in the RAM is lost.
MEMORY MANAGEMENT
• Primary Memory:
Cache memory — Cache memory is used to store the data and the related application that
was last processed by the CPU.
MEMORY MANAGEMENT
Secondary Memory: Secondary memory represents the external storage devices that are
connected to the computer. A storage device is either located in the CPU casing of the computer or
is connected externally to the computer. The secondary storage devices can be classifi ed as:

• Magnetic storage device — The magnetic storage devices store information that can be
read, erased and rewritten a number of times. These include fl oppy disk, hard disk and
magnetic tapes.

• Optical storage device — The optical storage devices are secondary storage devices that
use laser beams to read the stored data. These include CD-ROM, rewritable compact disk
(CD-RW), digital video disks with read only memory (DVD-ROM), etc.

• Magneto-optical storage device — The magneto-optical devices are generally used to


store
information, such as large programs, files and back up data.
Memory Unit: Amount of Data Stored in the Storage Unit

Bit: Binary Digit


Logical 0 or 1
Passive or Active State of a Component in an Electric Circuit

Nibble: Group of 4 bits

Byte: Group of 8 bits


Smallest Unit
Represents a Data Item or a Character

Word: Group of Fixed No. of bits Processed as a Unit


Varies from Computer to Computer
Fixed for Each Computer

Word-Size /Word Length: Length of a Computer Word


19
|<<

10
2 = 1024
Unit Description
KiloByte (KB) 1024 Bytes
MegaByte (MB) 1024 KB
GigaByte (GB) 1024 MB
TeraByte (TB) 1024 GB
PetaByte (PB) 1024 TB
Exabyte (EB) 1024 PB
Zettabyte (ZB) 1024 EB
Yottabyte (YB) 1024 ZB

20
Computer Program: Set of Instructions that tells the Computer Hardware what to do
Computer Software / Software: Collection of Computer Programs

21
Categories of Software
• System Software
• Application Software

22
System Software
Set of Programs
• used to Control Computer Activity and Computer Hardware
• Provides Platform for Application Software
• Required for Proper functioning of the Computer
• Interacts with Hardware
• Provides Platform for running Application Software
• Controls Overall Computer Hardware and Computer Activity
Simultaneously providing Service to User

23
Features of System Software
• Close to the System
• Fast in Speed
• Difficult to Design
• Difficult to Understand
• Less Interactive
• Smaller in Size
• Difficult to Manipulate
• Generally written in Low-level Language

24
Operating System
• Collection of Computer Programs that Guides the Computer Hardware to do Different
Activities under Variety of Conditions
• Performs Resource Management
• Provides Interface between the User and Machine
Device Drivers
• Set of Computer Program that Controls the Operation and Functionality of Different
Devices

25
Language Translator: Computer Program Translates High–Level Language to Machine
Language

Source Program / Code: Collection of Instructions written using a Programming Language


(High-Level Language / Assembly Language)
Object Program / Code: Machine Language Generated after Compiling the Source Program

26
Application Software
• Set of Programs
• Designed to Perform Specific task
• Requires System Software for its existence

27
Features of Application Software
• Close to the User
• Easy to Design
• More Interactive
• Slow in Speed
• Generally written in High-level Language
• Easy to Understand
• Easy to Manipulate
• Easy to Use
• Bigger in Size
• Requires Large Storage Space

28
Examples of Application Software
Payroll Software
Student Record Software
Inventory Management Software
Income Tax Software
Railways Reservation Software
Microsoft Office Suite Software
Microsoft Word
Microsoft Excel
Microsoft PowerPoint

29
Word Processors
Used for Creating Documents
Letters
Reports
Articles

in Required Format

Microsoft Word

Word Perfect

30
Spreadsheets
Used for
Storing Records
Simple Graphical Tools
Accounting Tools
Simple Calculations
Numerical Operations
on Data
Consists Rectangular Grids containing Different Cells
Microsoft Excel
Google Spreadsheets

31
Image Editors
Used for manipulation like
Rotation
Cropping
Zooming
Changing Appearance
Adjusting Contrast
...
on Images
Adobe Photoshop
Adobe Illustrator
Picasa
Microsoft Paint
...

32
DataBase Management System (DBMS)
Used for
Storing
Extraction
Manipulation
of Data
Microsoft Access
Oracle
MySQL
SyBase
INGRES
...

33
|<<

Web Browsers
Used for
Accessing world wide web (www)
Google Chrome
Firefox
Microsoft Edge
Torch
...

34
|<<
Relationship between Hardware and Software
Hardware and Software : Mutually Dependent on each other
Work together to Make Computer Produce Useful Output
Software cannot be Utilized without Supporting Hardware
Hardware without Set of Programs to Operate upon cannot be Utilized and Useless
Relevant Software should be Loaded into the Hardware to Get Particular Job Done on the Computer
Hardware : One-time Expense
Software Development
Very Expensive
Continuing Expense
Software : Interface between User and Hardware
Hardware is 'Heart' of Computer System,
Software is its 'Soul'
Hardware and Software Complementary to each other 35
Programming Languages
• Basic Building Blocks for all Software

• Used to Develop Software


• Indicates Computers What to Do

Classification of Programming Languages

36
Machine Languages
• Combination of 0s and 1s
• Computer understands only Machine Language
Advantages
• Translation Free
Directly Executed without any Translation
• High Speed
Extremely Fast Execution
Disadvantages
• Machine Dependent
Program Developed for One System
Does not Execute on Other System
• Complex Language for Programming : Very Difficult for Programmer
to Remember and Write the Instructions
• Error Prone: Very Tedious Task
• Time Consuming

37
Assembly (Low Level) Languages
• Binary Bits Replaced by Certain Keywords (Mnemonic)
Mnemonics
• Abbreviated Letters
• Easier to Remember
• ADD / SUB / MUL / DIV / INC / …

Assembler
• Converts Assembly Language into Machine Language
• Faster Compared to High Level Language
• Slower than Lowest Level Language (Machine Language)
38
Assembly (Low Level) Languages
Advantages
• Easy to Understand and Use
Mnemonic Codes
Easy to Use and Remember
Speed: Executes Faster than Program written High Level Language
Disadvantages
• Machine Dependent
Program Developed for One System
Does Not Execute on Other System
• Difficult To Learn
• Slow Program Development Time
Slow Process
Compared to High Level Language
39
High Level Languages
• English like
• Portable
Main Advantage
Easy to Read, Write and Maintain
BASIC Beginners All purpose Symbolic Instruction Code
FORTRAN FORmula TRANslation
COBOL COmmon Business Oriented Language
Pascal Great Mathematician Blaise Pascal
Ada Lady Programmer Ada (Military Applications)
C Dennis Ritchie
C++ Object Oriented Language
LISP LISt Processing (Artificial Intelligence)
PROLOG PROgramming in LOGic (LOGic PROgramming)
Python
… 40
High Level Languages
Compiler / Interpreter

Converts High Level Language into Machine Language


Compiler
Translates Entire High-level Language Program into Machine Language
FORTRAN, COBOL, Pascal, C, C++, C#, Java, …

Interpreter
Translates High Level Language Program into Machine Language, Instruction by
Instruction
BASIC, Ada, LISP, PROLOG, …
41
High Level Languages
Advantages
• Easy to Use and Understand
English Like

• Machine Independent
Portable
Programs Executed with Little or No Modification at all on any Computer

• Debugging Easy
Errors Detected and Located Easily

• Easy to Maintain Program

Disadvantages
• Poor Control on Hardware
Difficult to Access and Control Hardware Directly

• Slow Execution 42
High Level Languages |<<

Categories
Object Oriented
Procedural

Procedure Oriented Programming Language


• Specifies Sequence of Steps
in order to Perform Particular Task
• Divided into
Subroutines
Structures
Functions
BASIC, FORTRAN, COBOL, Pascal, C, …

Object Oriented Programming Language


• Data (Variables) and Code Combined to form Objects
• Allows more Effective Code Duplication
• Data, Functions and Subroutines
Encapsulated to form Objects
43
C++, Java, …
Problem Solving using Computers
• Problem Analysis
• Program Design
• Algorithm
• Flowchart
• Pseudo Code
• Coding
• Compilation and Execution
• Debugging and Testing
• Program Documentation
• Problem Analysis
Process of Defining a Problem
and Decomposing Overall System into Smaller Parts
to Identify Possible Inputs, Processes and Outputs
associated with the Problem

44
Program Design
Preparing
Algorithms
Flowcharts
Pseudo Code
Algorithm
Step-by-step Procedure
for Solving a Problem in a Finite No. of Steps
in Human Readable Language
Flowchart
Graphical Representation
Explains Sequence of Operations to be Performed
in order to Solve a Problem under Consideration using Standard Symbols
Pseudo Imitation
Code Instructions
Pseudo Code
Structured English for Describing Algorithms Concisely
45
|<<

• Coding (Programming): Process of Writing Actual Program


Source Code Any High Level / Assembly Language

• Compilation: Transformation from Source Code (Human Readable) into


Machine Code (Computer Executable)

• Execution: Run (Process) the Program Instructions (Statements)

• Bug: Error in the Program Instructions

• Debugging : Finding Errors and Removing them

• Testing: Verifying the Program working as per the Given Requirements

• Documentation: Details about the Program


46

You might also like