KEMBAR78
CP Module1 | PDF | Computer Data Storage | Programming
0% found this document useful (0 votes)
51 views37 pages

CP Module1

Module 1 introduces the fundamentals of computers and the C programming language, covering topics such as computer structure, input/output devices, and program design. It outlines the evolution of computers from vacuum tubes to artificial intelligence, detailing the characteristics, classifications, and applications of various computer types. Additionally, it explains the difference between data and information, the basic organization of computers, and the major operations performed by a computer.

Uploaded by

Sree Sreeja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views37 pages

CP Module1

Module 1 introduces the fundamentals of computers and the C programming language, covering topics such as computer structure, input/output devices, and program design. It outlines the evolution of computers from vacuum tubes to artificial intelligence, detailing the characteristics, classifications, and applications of various computer types. Additionally, it explains the difference between data and information, the basic organization of computers, and the major operations performed by a computer.

Uploaded by

Sree Sreeja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

1 Module-1: Introduction to C

Module 1:
Introduction to C: Introduction to computers, input and output devices,
designing efficient programs. Introduction to C, Structure of C program,
Files used in a C program, Compilers, Compiling and executing C
programs, variables, constants, Input/output statements in C.

What is Computer?

• Computer is an electronic device, which takes input from the user in the form
of data and instructions.
• Once the computer receives the data, it waits for the user’s instructions to
process the data.
• On receiving the instructions from the user, the computer processes the data
and generates the output and displays it to the user.
• The data that is given as an input to the computer can be text, numerals,
audio, video and image etc.

In simple terms computer can be defined as,


“An electronic device which accepts the data, performs the required
mathematical and logical operations at high speed and outputs the
result”.

Tasks of the Computer:

• Input: Sending the data and command to the computer is known as input.
• Processing: Work done by the computer with the help of processing hardware
and software to produce results is known as processing.
• Output: The result displayed by the computer is called as output.
• Storage: A place to save results inside or outside the computer is known as
storage.

Characteristics of computers:

 Speed: Computers can do millions of tasks every second. Their speed is


measured in very tiny units like nanoseconds (one billionth of a second)
and picoseconds (one trillionth of a second).

 Accuracy: Computers give precise results as long as the input and


instructions are correct. If you give wrong information, you'll get wrong
results. This is known as “garbage-in, garbage-out.”

 Automation: Computers can carry out tasks on their own without


needing help from people.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


2 Module-1: Introduction to C

 Diligence: Unlike humans, computers don’t get tired from doing the
same task over and over.

 Versatile: Computers can handle different kinds of tasks at the same


time.

 Memory: Computers have both internal (primary) memory and external


(secondary) memory to save data and programs.

 No IQ: Computers don’t think for themselves. They need instructions to


know what to do.

 Economical: Computers are a smart short-term investment that can


lead to long-term savings in time, money, and energy.

What is difference between data and information?

• Data is a raw fact.


• Information is a processed data.
For example, the date of birth is the data and calculating the age using date of
birth is information.

Types of stored program Computers

Fig: Von Neumann Architecture with shared memory for instructions and
data

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


3 Module-1: Introduction to C

• A computer with Von Neumann Architecture stores data and instructions in


the same memory.
• There is a serial machine in which data and instructions are selected one at a
time.
• Data and instructions are transferred to and from memory through shared
data bus.
• Since there is a single bus to carry data and instructions, process of
execution becomes slower.

Fig: Von Neumann Architecture with separate memory for instructions


and data

Instruction DATA ADDRESS


Address

Read/Write Data
Instruction
s

• Due to the disadvantage of previous architecture, Harvard University


proposed a stored program concept in which there was a separate memory to
store data and instructions.
• Instructions are selected serially from the instruction memory and executed
in the processor.
• When an instruction needs data, it is selected from the data memory and
hence the execution becomes faster.

History of Computers:

First Generation (1942-1955): Vacuum Tubes

 These computers used thousands of vacuum tubes.


 They used electromagnetic relays for memory and punch cards to store
data and instructions.
 Programming was done in basic machine or assembly languages.

Advantage: They were the fastest calculators of their time.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


4 Module-1: Introduction to C

Disadvantages: They generated a lot of heat, used a lot of electricity, were


large and heavy, needed constant maintenance, had limited commercial use,
and were very expensive.

Second Generation (1955-1964): Transistors

 These computers used transistors, which were more reliable, cheaper,


smaller, and cooler than vacuum tubes.
 They used magnetic core memory and magnetic tapes/disks for storage.
 Programming was done in higher-level programming languages.

Advantages: They used less electricity, generated less heat, were faster and
more reliable, and had better memory.

Disadvantage: Transistors were put together by hand, making them hard


and expensive to produce.

Third Generation (1964-1975): Integrated Circuits

 These computers used integrated circuits (ICs), which had many


components like transistors on a single chip to reduce wiring.
 They used large magnetic core memory and magnetic tapes/disks for
storage.
 Programming was done in high-level programming languages.

Advantages: They were faster, could handle one million transactions per
second, were smaller and cheaper, and had better memory for scientific and
business use.

Disadvantage: They were still hard to maintain and could heat up quickly.

Fourth Generation (1975-1989): Microprocessors

 These computers used integrated circuits with large-scale integration


(LSI) and very large-scale integration (VLSI).
 They used semiconductor memory and portable storage like magnetic
tapes and floppy disks.
 Programming was done in higher-level languages like C and C++.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


5 Module-1: Introduction to C

Advantages: They were smaller, cheaper, faster, used less electricity,


generated less heat, and were easier to use with graphical user interfaces
(GUIs). They became common in homes and offices.

Disadvantage: They weren’t intelligent systems.

Fifth Generation (1989-Present): Artificial Intelligence

 These computers use advanced integrated circuits with ultra-largescale


integration (ULSI).
 They use semiconductor memory and portable storage like magnetic
tapes and floppy disks.
 Programming is done in high-level languages like Java, Python, and C#.

Advantages: They are smaller, cheaper, faster, more powerful, reliable, use
less power, and have advanced features.

Comparison table

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


6 Module-1: Introduction to C

Classification of Computers:

1) Supercomputers:

 Fastest and Most Powerful: Supercomputers are the top tier of


computing power. They are designed to handle incredibly complex tasks
that require massive amounts of calculations.
 Purpose: Developed in the 1980s, they help scientists and researchers
analyze huge datasets and solve problems in fields like climate science
and physics.
 Speed: These computers can perform trillions of calculations every
second, making them essential for tasks that regular computers cannot
handle.
 Users: A supercomputer can support thousands of users simultaneously,
making it ideal for research institutions and universities.
 Uses: They're used for things like predicting the weather, studying
nuclear energy, designing aircraft, and managing financial transactions
in banking.
 Examples: Notable supercomputers include CRAY-1 and CRAY-2, known
for their speed and capabilities.

2) Mainframe Computers:

 Large but Smaller than Supercomputers: Mainframes are big


computers but not as powerful as supercomputers. They can handle
large volumes of transactions and data processing.
 Special Environment Needed: They require a clean, air-conditioned
room to operate efficiently, making them expensive to maintain.
 Multi-User Support: Mainframes can manage many users at the same
time and can have multiple processors working together.
o Dumb Terminals: Simple terminals that connect to the
mainframe, allowing users to access the system without much
processing power.
o Intelligent Terminals: Have their own processing capabilities but
rely on the mainframe for storage.
 Uses: They are typically used in large organizations like banks, airlines,
and universities where many people need to access data at once.
 Examples: IBM S/390 and Control Data CYBER 176 are well-known
mainframes.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


7 Module-1: Introduction to C

3) Minicomputers:

 Smaller and Cheaper than Mainframes: Minicomputers are less


powerful and more affordable than mainframes, making them accessible
for smaller organizations.
 Also Called Midrange Computers: They fill the gap between powerful
mainframes and personal computers.
 Wide Use: Common in business, education, hospitals, and government
where moderate computing power is needed.
 Single or Multi-User: Some minicomputers can be used by one person,
while others support multiple users for tasks like data analysis or
inventory management.
 First Developed in the 1960s: The first minicomputer was created by
Digital Equipment Corporation, changing how businesses processed
data.

4) Microcomputers:

 Commonly Known as PCs: Microcomputers are what most people use


every day, like desktops and laptops.
 First Microcomputer: The IBM-PC, introduced in 1981, marked the
beginning of personal computing for the masses.
o Desktop PCs: The most popular type, suitable for home and office
use.
o Laptops: Portable computers that can easily fit in a bag and are
convenient for travel.
o Workstations: More powerful than regular PCs, designed for tasks
that need high-quality graphics and speed, like video editing or 3D
modeling.
 Advantages: Workstations offer high-resolution graphics, making them
ideal for creative professionals.
 Disadvantages: They can be expensive and are usually not portable.

Network Computers:

 Lower Power than Desktops: These computers are designed to be part


of a network, meaning they don’t need as much power or storage on their
own.
 Functionality: They work by connecting to a network, allowing users to
access data and applications stored elsewhere, like on a server.
 Internet PCs: Some are specifically made to connect only to the Internet,
often used for online tasks.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


8 Module-1: Introduction to C

 Examples: Web TV allows users to browse the Internet through their


television, showing how network computers can be versatile.
 Cost-Effective: These computers are generally cheaper to buy and
maintain, making them attractive for businesses and homes.

Smartphones:

 Handheld Devices: Smartphones combine mobile phone features with


those of a PDA, allowing for calls, texts, and various apps.
 Features: Users can access email, browse the web, take photos, and
even listen to music—all in one device.
 Advantages: They are very portable and offer a wide range of
functionalities.
 Disadvantages: They can be larger than standard phones and often cost
more, with high replacement costs if damaged.

Tablet Computers:

 Similar to Laptops: Tablets are portable computers that look like a flat
slate and can be operated with a stylus (a special pen for touch screens).
 Portable: They are lightweight and easy to carry, making them great for
on-the-go use.
 Advantages: Users can write notes by hand, reducing the need for paper
and making note-taking easier.
 Disadvantages: Tablets can be more expensive than laptops and are
generally more delicate, making them prone to damage.

Applications of Computers:

 Word Processing:
o Description: Word processing software is essential for creating
and editing text documents. It allows users to format text, add
images, and collaborate on documents easily.
o Example: Microsoft Word is widely used in businesses, schools,
and homes for tasks like writing reports, resumes, and essays.
Features like spell check and templates enhance productivity.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


9 Module-1: Introduction to C

 E-Business (B2C):
o Description: E-business enables companies to sell products and
services directly to consumers over the Internet. This model has
transformed retail and consumer behavior.
o Example: Amazon is a leading example of B2C e-business, offering
everything from books to electronics. Customers can shop online,
read reviews, and receive products quickly, revolutionizing the
shopping experience.
 Electronic Banking:
o Description: Also known as online banking, this application allows
users to conduct banking activities from their homes or on the go.
It provides convenience and accessibility.
o Example: Services like PayPal and mobile banking apps enable
users to check balances, transfer funds, pay bills, and even deposit
checks using their smartphones, making financial management
easier.
 Bioinformatics:
o Description: This interdisciplinary field combines biology and
computer science to analyze complex biological data, especially
useful in genomics and drug discovery.
o Example: Bioinformatics tools are used in genetics to sequence
DNA and identify genetic markers for diseases, which is crucial for
personalized medicine and targeted therapies.
 Geographic Information System (GIS):
o Description: GIS technology allows for mapping and analyzing
spatial data. It is essential for urban planning, environmental
monitoring, and disaster management.
o Example: ArcGIS is a popular GIS software that helps
governments and organizations visualize data, track changes in
land use, and manage resources effectively.
 Weather Forecasting:
o Description: Computers play a key role in meteorology, using data
models to predict future weather conditions. Accurate forecasting
is vital for safety and planning.
o Example: Weather apps and websites rely on complex algorithms
and satellite data to provide real-time updates and forecasts,
helping individuals and businesses make informed decisions.
 Multimedia and Animation:
o Description: This application involves combining various forms of
media—text, images, audio, and video—to create engaging content
for entertainment and education.
o Example: Software like Adobe Premiere and After Effects is used in
film and video production to create stunning visual effects and
animations, enhancing storytelling.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


10 Module-1: Introduction to C

 Decision Support Systems:


o Description: These systems analyze business data to help
managers make informed decisions. They often include data
visualization tools and reporting features.
o Example: Business intelligence platforms like Tableau or Power BI
provide insights into sales trends, customer behavior, and
operational efficiencies, helping organizations optimize
performance.
 Simulation:
o Description: Simulations use computer models to replicate real-
world processes, allowing for testing and training without risk.
They are widely used in various industries.
o Example: Flight simulators are essential for pilot training,
providing realistic scenarios that help pilots practice navigation
and emergency procedures without leaving the ground.
 Expert Systems:
o Description: These AI-driven systems mimic human expertise to
assist in decision-making in specific fields, such as healthcare or
finance.
o Example: Medical expert systems can analyze patient symptoms
and medical histories to recommend diagnoses and treatment
options, helping doctors provide better care.

Basic Organization of Computers

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


11 Module-1: Introduction to C

What does a computer do?


A computer is an electronic device which performs 5 major operations.
• Accepting data or instructions.
• Storing data
• Processing data
• Displaying results
• Controlling and coordinating all operations inside a computer.

Input:
• The process of entering the data and instructions into the computer system is
called Input.
• The data and instructions can be entered by using different input devices
such as keyboard, mouse, scanner, and trackball.

• Note that computers understand binary language, which consists of only two
symbols (0 and 1), so it is the responsibility of the input devices to convert the
input data into binary codes.

Storage:
• Storage is the process of saving data and instructions permanently in the
computer so that they can be used for processing.
• A computer has 2 types of storage area:
1. Primary storage
2. Secondary storage

1. Primary storage:
• Primary storage, also known as the main memory, is the storage area that is
directly accessible by the CPU at very high speeds.
• It is used to store the data and parts of programs, the intermediate results of
processing, and the recently generated results of jobs that are currently being
worked on by the computer.
• Primary storage space is very expensive and therefore limited in capacity.
• Another drawback of main memory is that it is volatile in nature; that is, as
soon as the computer is switched off, the information stored gets erased.
• Hence, it cannot be used as a permanent storage of useful data and programs
for future use. An example of primary storage is random access memory (RAM).

2. Secondary storage:
• Secondary storage is also known as auxiliary memory, this memory is just the
opposite of primary memory. It overcomes all the drawbacks of the primary
storage area.
• It is cheaper, non-volatile, and used to permanently store data and programs
of those jobs that are not being currently executed by the CPU.
• Secondary memory supplements the limited storage capacity of the primary
memory. An example is the magnetic disk used to store data, such as C and D
drives, for future use.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


12 Module-1: Introduction to C

Output:
• Output is the process of giving the result of data processing to the outside
world (external to the computer system).
• The results are given through output devices such as monitor, and printer.
• Since the computer accepts data only in binary form and the result of
processing is also in binary form, the result cannot be directly given to the
user.
• The output devices, therefore, convert the results available in binary codes
into a human-readable language before displaying it to the user.

Control:
• The control unit (CU) is the central nervous system of the entire computer
system. It manages and controls all the components of the computer system.
• It is the CU that decides the manner in which instructions will be executed
and operations performed. It takes care of the step-by-step processing of all
operations that are performed in the computer.
• Note that the CPU is a combination of the arithmetic logic unit (ALU) and the
CU. The CPU is better known as the brain of the computer system because the
entire processing of data is done in the ALU, and the CU activates and
monitors the operations of other units (such as input, output, and storage) of
the computer system.

Processing:
• The process of performing operations on the data as per the instructions
specified by the user (program) is called processing.
• Data and instructions are taken from the primary memory and transferred to
the ALU, which performs all sorts of calculations.
• The intermediate results of processing may be stored in the main memory, as
they might be required again.
• When the processing completes, the final result is then transferred to the
main memory.
• Hence, the data may move from main memory to the ALU multiple times
before the processing is over.

Inside the Computers

CPU:
• The CPU is the brain of the computer. It performs all calculations and
controls the devices connected to the computer system.
• The faster the CPU, the quicker programs can process the instructions.

RAM:
• A fast CPU is of no use if the computer does not have sufficient RAM.
• RAM is the computer's memory which stores information used by applications
that are currently being executed by the CPU.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


13 Module-1: Introduction to C

• More memory means more applications can be executed at the same time
without degrading the system's performance.

Hard disk drive (HDD):


• The HDD of the computer is the secondary memory of the computer system
where information is stored permanently.
• All types of data, documents, and programs are stored on the hard disk.
• The larger the hard disk, the more the amount of data that can be stored on
the drive.
• Though the size of the HDD does not affect the speed of execution of the
program, it does affect the speed at which the user can access his/ her files.

Video card:
• The video card is a board that plugs into the motherboard of the computer
and generates images for display.
• Many video cards these days have their own RAM and processor to enhance
the speed of the graphics display.
• Many computers come with an in-built video chip.
• In such a computer, a separate video card is used only if the computer has to
be used for high-end multimedia work or to play video games.

Sound card:
• As with video cards, sound cards are expansion boards that are used to
enable a computer to manipulate sound.
• For example, sound cards allow the users to plug in speakers and a
microphone. Some sound cards also provide the jacks for hooking your
computer up to a common stereo.
• These days, many computers come with a built-in sound chip, which makes it
unnecessary to buy a separate card unless a higher quality of sound is needed.

Modem:
• A modem (modulator-demodulator) is a device that enables the computer to
use a telephone line to communicate and connect to the Internet.

Network card:
• A network card is used to connect the computer either to other computers or
to the Internet (in case you are using a fast Internet connection such as cable
or DSL).

Fans:
• There are one or more fans inside the computer to keep the air moving and
the computer cool.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


14 Module-1: Introduction to C

Cables:
• There are multiple wires inside the computer that are flat, ribbon-like cables.
• They are used to provide power and communication to the various parts
inside the computer.

Input and Output Devices

Input devices:
Input devices allow users to send data and commands to a computer, enabling
interaction and control. They convert physical actions or signals into digital
data that the computer can process.

1. Keyboard

 What It Is: The keyboard is a tool that lets you type letters, numbers,
and commands into a computer, much like a typewriter.
 Layout: It has many keys, including letters (A-Z), numbers (0-9), and
special keys like "Enter," "Shift," and "Function" keys that perform
specific tasks.
 Numeric Keypad: This is a group of number keys usually located on the
right side of the keyboard, making it easier to enter numbers quickly,
similar to a calculator.
 Advantages: Keyboards are generally user-friendly and affordable,
making them accessible for everyone.
 Limitations: They aren’t suitable for tasks like drawing pictures, and
moving the cursor around can be slower than using a mouse.

2. Mouse

 What It Is: A mouse is a small, handheld device that allows you to


control a pointer on the computer screen by moving it across a flat
surface.
 How It Works: You can click on items to select them, drag items to move
them, and scroll through pages using the mouse.
 Types: There are different types of mice, including:
o Mechanical Mouse: Uses a ball underneath to detect movement.
o Optical Mouse: Uses light to track movement and is more common
today.
o Cordless Mouse: Connects to the computer wirelessly, giving you
more freedom of movement.
 Advantages: Mice are easy to use and make it quick to navigate through
applications and documents.
 Limitations: They need some desk space to move around, and
mechanical mice require cleaning to keep them working properly.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


15 Module-1: Introduction to C

3. Touchpad

 What It Is: A touchpad is a flat, rectangular surface found on laptops


that lets you control the cursor without needing a separate mouse.
 How It Works: You move your fingers across the touch-sensitive surface
to move the cursor on the screen. Tapping the surface is like clicking a
mouse button.
 Space-Saving: Since it’s built into the laptop, it saves space and makes
the device more portable.
 Advantages: Touchpads are convenient and intuitive, especially for users
who prefer a minimalist setup.
 Limitations: Some people find them less precise for detailed tasks, like
graphic design, compared to a traditional mouse.

4. Scanner

 What It Is: A scanner is a device that captures images or text from


physical documents and converts them into digital files that can be saved
on a computer.
 Types:
o Flatbed Scanner: You place a document on a glass surface, and
the scanner moves a light across it to capture the image.
o Handheld Scanner: You move the scanner over the document
manually.
 Uses: Scanned documents can be saved, edited, or shared via email or
cloud services, making it easy to digitize important papers.
 Advantages: Scanning preserves the quality of documents and helps
prevent loss of important information.
 Limitations: Scanners can be more expensive than simpler input
devices, and the digital files they create may take up more space on your
computer.

5. Optical Character Recognition (OCR)

 What It Is: OCR is a technology that converts printed text from scanned
documents into editable digital text.
 How It Works: The OCR process involves scanning the document and
analyzing the shapes of characters to translate them into text that can be
edited or searched.
 Applications: This technology is useful for turning books, forms, and
other printed materials into digital formats that are easy to edit and
store.
 Advantages: OCR makes it simple to digitize printed materials, allowing
for easy editing and sharing.
 Limitations: It may have difficulty recognizing certain fonts or poorly
printed documents, which can lead to errors in the digital text.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


16 Module-1: Introduction to C

OUTPUT DEVICES

Output devices take information from a computer and present it in a human-


readable form. They convert digital data into formats we can see, hear, or
touch.

1. Monitors

Monitors display video and graphics. Key points include:

1. Types: The main types are CRT, LCD, and Plasma, each with different
technologies.
2. Display Quality: CRTs provide good image quality, while LCDs and
Plasmas offer clearer and brighter displays.
3. Space and Weight: CRTs are bulky and heavy, while LCDs and Plasmas
are slim and lightweight.
4. Power Consumption: CRTs consume more power than LCDs and
Plasma monitors, which are more energy-efficient.
5. Viewing Angles: Plasmas have the best viewing angles, while LCDs may
struggle with color clarity when viewed from the side.

2. Projectors

Projectors display images on larger screens. Important points include:

1. Functionality: They take video signals from a computer and project


them onto surfaces like screens or walls.
2. Types: The two main types are LCD projectors and DLP projectors.
3. Brightness: DLP projectors can display clearer images in both light and
dark environments, while LCD projectors work best in dark settings.
4. Applications: Used for presentations, home theaters, and educational
purposes.
5. Portability: Many projectors are lightweight and easy to transport,
making them convenient for various settings.

3. Printers

Printers produce physical copies of documents. Key points include:

1. Types: There are impact printers (like dot matrix and daisy wheel) and
non-impact printers (like inkjet and laser).
2. Print Quality: Non-impact printers generally offer better quality and
color output compared to impact printers.
3. Speed: Laser printers are faster, making them suitable for high-volume
printing, while impact printers are slower.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


17 Module-1: Introduction to C

4. Cost: Inkjet printers have a lower initial cost but higher maintenance
costs due to ink cartridges, while laser printers are more cost-effective in
the long run.
5. Uses: Printers are used for everything from simple documents to high-
quality color prints for presentations.

4. Speakers

Speakers output sound from computers and enhance audio experiences.


Important points include:

1. Sound Quality: Good quality speakers produce clear and rich sound for
music, movies, and games.
2. Types: Speakers come in various types, including standalone speakers,
soundbars, and headphones.
3. Applications: Used in home theaters, offices, and for personal listening
experiences.
4. Volume Control: Speakers can project sound across large spaces, while
headphones offer personal listening without disturbing others.
5. Connectivity: Many speakers connect via Bluetooth or USB, making
them versatile for different devices.

5. Plotters

Plotters are specialized printers for creating high-quality graphics. Key points
include:

1. Precision: They are designed for producing detailed vector graphics,


making them ideal for technical drawings.
2. Types: Common types include drum plotters and flatbed plotters, each
with different paper handling methods.
3. Applications: Used in fields like engineering, architecture, and design for
creating maps, blueprints, and designs.
4. Quality: Plotters provide superior print quality compared to standard
printers, especially for large-format prints.
5. Speed: They can print multiple lines of a design simultaneously, making
them efficient for large projects.

PROGRAMMING PARADIGMS

What is a Programming Paradigm?


A programming paradigm is a basic approach to programming that defines how
we write and organize code. It affects how a program is structured and what
features the programming language provides. Understanding different
paradigms helps programmers choose the best way to solve problems.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


18 Module-1: Introduction to C

Types of Programming Paradigms

1. Monolithic Programming
Explanation: This approach involves writing one large program without
breaking it down into smaller parts. All code is in one place, which
makes it straightforward but also problematic.
Features:
 Single Module: Everything is contained in one big piece of code.
 Difficult Maintenance: Since everything is together, fixing bugs
or making changes can be hard and time-consuming.
 Shared Data: All parts of the program can access and change the
same data, which can lead to errors if not managed carefully.
 Examples: Assembly Language and BASIC are commonly used in
monolithic programming.

2. Procedural Programming
o Explanation: This style focuses on writing programs as a series of
instructions or procedures. It emphasizes the steps needed to
complete tasks.
o Advantages:
 Clear Goal: The main focus is to write correct programs that
perform specific tasks.
 Easier to Write: Generally simpler than monolithic
programming, as it allows for structured sequences of
commands.
o Disadvantages:
 No Reusability: It’s harder to use the same code in different
programs, as each program is written independently.
 Time-Consuming: Writing and maintaining procedural
programs can take more effort.
 Global Data Issues: Shared data can be modified
accidentally, leading to bugs.
o Examples: Languages like C and Pascal are typical procedural
languages.

3. Structured Programming
o Explanation: This approach breaks down a program into smaller,
manageable modules. Each module can be developed and tested
independently, making the entire program easier to manage.
o Features:
 Top-Down Design: The overall program is planned first, and
then broken into smaller parts.
 Modular Code: Each module can be written, tested, and
reused in other programs, promoting efficiency.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


19 Module-1: Introduction to C

Avoiding Code Repetition: By using subroutines,


programmers can avoid rewriting the same code.
o Examples: FORTRAN and COBOL are popular structured
programming languages.

4. Object-Oriented Programming (OOP)


o Explanation: This paradigm organizes code around data and the
operations that can be performed on that data, grouping them into
units called objects. This helps in modeling real-world scenarios.
o Features:
 Data Encapsulation: Important data is kept safe from
outside interference, making programs more secure.
 Flexibility: New features can be added easily by creating
new objects or modifying existing ones.
 Bottom-Up Approach: Focuses on building small pieces
(objects) first, then combining them to form larger systems.
o Advantages:
 Team Collaboration: Many programmers can work on
different parts of a large program at the same time,
improving productivity.
 Reuse of Code: Objects can be reused across different
programs, saving time.
o Disadvantages:
 Focus on Functions: Sometimes it may not emphasize data
management enough.
 Shared Data Risks: Data shared among objects can still be
altered unintentionally.
o Examples: Common OOP languages include Java, C++, and
Python.

Note: Understanding these programming paradigms helps programmers decide


the best way to tackle a project. Each has its strengths and weaknesses, and
the right choice can lead to better, more efficient code.

Design and Implementation of Efficient Programs

 Requirement Analysis
 Explanation: This phase is crucial for understanding what users expect
from the software and why it needs to be developed.
 Key Activities:
 Gather User Expectations: Collect information from users to identify
their needs and expectations.
 Analyze Requirements: Review the gathered information to define clear
objectives for the software.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


20 Module-1: Introduction to C

 Document Requirements: Write down all requirements to avoid


confusion or misunderstandings later.
 Assess Capabilities: Analyze the functionality, performance, and
compatibility of hardware and software components needed for the
project.
 Design
o Explanation: This phase involves creating a detailed plan for how
the software will function before any coding begins.
o Key Activities:
 Create a Plan: Develop a structured approach that will guide
the entire development process.
 Break Down Structure: Divide the core structure of the
software into smaller, manageable modules.
 Specify Solutions: For each module, outline how it will work
using algorithms, flowcharts, or pseudocode to visualize the
logic.
 Implementation
o Explanation: In this phase, the designed algorithms are translated
into actual code using a programming language.
o Key Activities:
 Convert Algorithms to Code: Write program code based on
the designed algorithms using a high-level programming
language.
 Choose Programming Language: Select a language based
on the type of program (system vs. application).
 Test the Code: Ensure the code functions correctly by
running tests during the development process.
 Ensure Compatibility: Verify that the software works with
the specified hardware and software as detailed in the
requirements.
 Testing
o Explanation: This phase ensures that all components of the
software work together as a complete system.
o Key Activities:
 Integrate and Test Modules: Combine all modules and test
them together to identify any issues that arise from their
interaction.
 Use Test Data: Test the software with various inputs to
confirm it meets the requirements identified in the analysis
phase.
 Software Deployment, Training, and Support
o Explanation: After testing, the software is made available to users,
and support is provided to ensure smooth adoption.
o Key Activities:

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


21 Module-1: Introduction to C

Deploy the Software: Release the software into a production



environment for users to access.
 Provide Training: Conduct training sessions to familiarize
users with the software, helping them overcome any
resistance to change.
 Offer Ongoing Support: Provide assistance to users as they
adapt to the new software and troubleshoot any issues.
 Maintenance
o Explanation: This ongoing phase involves addressing problems
and making improvements after the software is in use.
o Key Activities:
 Fix Bugs and Add Features: Continuously resolve newly
discovered issues and implement enhancements based on
user feedback.
 Monitor Maintenance Costs: If maintenance costs exceed
25% of the previous phases' costs, it may indicate issues
with earlier development stages, suggesting the need to
improve or rebuild parts of the software.

Algorithms
 What They Are: An algorithm is a structured sequence of steps
designed to solve a specific problem.
 Key Features:
o Finite Steps: Must complete in a limited number of steps,
ensuring it provides an answer.
o Clarity and Precision: Should be clear and unambiguous, with
each step well-defined.
o No Infinite Loops: Must avoid repeating instructions endlessly.
o Desired Outcome: Should produce the expected result when
executed.
 Control Structures in Algorithms
 Decision: Decision statements are used when outcomes depend on
specific conditions. For example: if x = y, then print "EQUAL".
 Repetition: This involves executing steps multiple times using loops
like while, do-while, and for, which continue until a condition is met.
 Sequence: Each step in the algorithm is executed in a defined order.

Flowcharts
 What They Are: Flowcharts visually represent a process, helping to
clarify its logic.
 Key Features:
o Symbolic Representation: Different shapes represent various
steps, connected by arrows to indicate the flow of logic.
o Visualization: Helps identify flaws and bottlenecks in complex
processes, making it easier to understand the workflow.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


22 Module-1: Introduction to C

Pseudocode
 What It Is: Pseudocode is a simplified, informal description of an
algorithm designed for human readability.
 Key Features:
o High-Level Outline: Focuses on the logic rather than technical
details, omitting unnecessary elements like variable declarations.
o Easy Translation: Can be easily converted into actual
programming code.
o Descriptive Language: Uses simple English phrases to explain
tasks within the algorithm, enhancing understanding without
specific programming syntax.
 Note: This structured approach to software development ensures that
each phase is thoroughly planned and executed, resulting in efficient
programs that meet user needs. Each step plays a vital role in
maintaining the overall quality and effectiveness of the software.

TYPES OF ERRORS

When writing programs, errors can occur that affect the program's output or
prevent it from compiling. Understanding these errors is crucial for effective
programming.

1. Run-Time Errors
o What They Are: These errors happen while the program is
running.
o Causes:
 Dividing by zero.
 Opening a file that already exists.
 Running out of memory.
 Trying to calculate the square root or logarithm of a negative
number.
o Impact: Run-time errors can stop the program unexpectedly. To
avoid this, the code should be able to handle these errors
gracefully. This ability is known as robustness.
2. Compile-Time Errors
o What They Are: These errors occur during the compilation process
when the code is checked for correctness.
o Types:
 Syntax Errors: Occur when the rules of the programming
language are broken. For example, writing int a: instead of
int a; will cause a syntax error.
 Semantic Errors: These are errors that, while syntactically
correct, do not make sense in the program’s context. For
example, a * b = c; is incorrect; it should be c = a * b;.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


23 Module-1: Introduction to C

3. Logical Errors
o What They Are: These errors occur when the program runs but
produces incorrect or unexpected results.
o Detection: Logical errors are not caught by the compiler, so
programmers must review their code carefully or use a debugger to
find these errors.
o Example: If you intended to write c = a + b; but mistakenly wrote c
= a * b; , the statement is syntactically correct but logically wrong.
4. Linker Errors
o What They Are: These occur when the linker cannot find the
definition for a declared function.
o Example: If you use clrscr(); but forget to include the header file
conio.h, a linker error will occur.

Testing Approaches

Testing is essential for ensuring that a program functions correctly and meets
its requirements. Different methods focus on various aspects of the software.

 Unit Testing: This method tests individual modules or units of the


program to verify that each one behaves as expected.
 Integration Testing: After unit testing, this approach combines tested
units and checks their interactions. The goal is to identify any errors that
arise when the units are integrated.
 System Testing: This method tests the entire system as a whole. For
example, if a program consists of three modules, each module is tested
individually first, and then the whole system is tested together.

Debugging Approaches

Debugging involves identifying and fixing errors in the code. Various methods
can help locate issues.

 Brute-Force Method: This technique involves examining CPU registers


and memory locations by printing them out. It’s the least efficient
method and is typically a last resort when other techniques fail.
 Backtracking Method: This method traces back from the point where
the error occurs to find its root cause. However, it can become complex
with large amounts of code due to the many possible paths to check.
 Elimination Method: In this technique, a list of potential causes for an
error is created. Tests are then conducted to eliminate each possibility. If
some tests indicate a specific cause, further investigation focuses on that
area to isolate the error.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


24 Module-1: Introduction to C

Introduction to C

• C was developed in the early 1970s by Dennis Ritchie at Bell Laboratories.


• C was initially developed for writing system software
• Today, C has become a popular language and various software programs are
written using this language.
• Many other commonly used programming languages such as C++ and Java
are also based on C.

Characteristics of C

 High-Level Language: C allows programmers to focus on solving


problems without worrying about machine code.
 Small Size: C has only 32 keywords, making it relatively easy to learn.
 Function Calls: C uses function calls extensively, which helps organize
code and make it reusable.
 Structured Programming: C supports structured programming,
allowing users to break down problems into smaller modules that
combine to form a complete program.
 Loose Typing: Unlike some languages, C allows variables to be treated
as different types (e.g., a character can be treated as an integer).
 Stable Language: C is known for its reliability and stability in software
development.
 Fast and Efficient: C programs use operators and data types effectively,
resulting in quick execution.
 Low-Level Programming: C enables bitwise operations, allowing for
detailed control over hardware.
 Portability: C programs can run on different computers with little or no
changes, making it a portable language.

Uses of C

 System Programming: C is mainly used for system programming


because it is efficient, portable, and can access specific hardware
addresses. This makes it ideal for creating operating systems and
embedded systems.
 Widely Accepted: Many professionals favor C, leading to the
development of compilers, libraries, and interpreters for other
programming languages being implemented in C.
 Intermediate Language: For convenience and portability, C is often
used as an intermediate language in other languages’ implementations.
Examples include compilers like BitC, Gambit, Glasgow Haskell
Compiler, Squeak, and Vala.
 End-User Applications: C is also widely used to develop applications
that end-users interact with.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


25 Module-1: Introduction to C

Structure of a C program
• A C program contains one or more functions
• The statements in a C program are written in a logical
sequence to perform a specific task.
• Execution of a C program begins at the main() function
• You can choose any name for the functions.
• Every program must contain one function that has its
name as main().
Where, #include refers to the preprocessor statement
used for the standard input/output functions and it
starts with the hash (#) symbol.

main( ):- Refers to the function from where the


execution of the program begins.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


26 Module-1: Introduction to C

Files used in C program

Source code file


• A source code is a list of commands that has to be assembled or compiled into
an executable computer program.
• The source code file contains the source code of the program. The file
extension of any C source code file is “.c”.
• This file contains C source code that defines the main function and maybe
other functions.
• The main() is the starting point of execution when you successfully compile
and run the program.
• A C program in general may include even other source code files (with the file
extension .c).

Header file
• When working with large projects, it is often desirable to make sub-routines
and store them in a different file known as header file. The advantage of header
files can be realized when
a) The programmer wants to use the same subroutines in different programs.
b) The programmer wants to change, or add, subroutines, and have those
changes be reflected in all other programs.
• Conventionally, header files names ends with a “.h” extension and its name
can use only letters, digits, dashes, and underscores.
• While some standard header files are available in C, but the programmer may
also create his own user defined header files.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


27 Module-1: Introduction to C

Standard Header file


Examples of standard header files are:
1. string.h: for string handling functions.
2. stdlib.h: for some miscellaneous functions.
3. stdio.h: for standardized input and output functions.
4. math.h: for mathematical functions
5. alloc.h: for dynamic memory allocation.
6. conio.h: for clearing the screen.

Object Files:
• Object files are generated by the compiler as a result of processing the source
code file.
• Object files contain compact binary code of the function definitions.
• Linker uses this object file to produce an executable file (.exe file) by
combining the of object files together.
• Object files have a “.o” extension, although some operating systems including
Windows and MS-DOS have a “.obj” extension for the object file.

Binary Executable File


• The binary executable file is generated by the linker.
• The linker links the various object files to produce a binary file that can be
directly executed.
• On Windows operating system, the executable files have “.exe” extension.

COMPILING AND EXECUTING C PROGRAMS

• The compiler translates the source code into an object code.


• The object code contains the machine instructions for the CPU, and calls to
the operating system API(Application Programming Interface).
• However, even the object file is not a executable file.
• Therefore, in next step, the object file is processed with another special
program called a linker.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


28 Module-1: Introduction to C

• While there is a different compiler for every individual language, the same
linker is used for object files regardless of the original language in which the
new program was written.
• The output of the linker is an executable or runnable file.

Using Comments
• It is a good programming practice to place some comments in the code to help
the reader understand the code clearly.
• Comments are just a way of explaining what a program does. It is merely an
internal program documentation.
• The compiler ignores the comments when forming the object file. This means
that the comments are non-executable statements.
C supports two types of commenting.
• // is used to comment a single statement. This is known as a line comment.
A line comment can be placed anywhere on the line and it does not require to
be specifically ended as the end of the line automatically ends the line.
• /* is used to comment multiple statements. A /* is ended with */ and all
statements that lie within these characters are commented.

C tokens
• Tokens are the basic building blocks in C language.
• It is the smallest individual unit in C program.
• A program is constructed using a combination of these tokens. 6main types of
tokens in C are:

Character set in C
• In C, character means any letter from English alphabet, a digit or a special
symbol used to represent information.
• The character set of C can therefore be given as:
1. English alphabet: Include both lower case (a-z) as well upper case (A-Z)
letters.
2. Digits: Include numerical digits from 0 to 9.
3. Special characters: Include symbols such as ~, @, %, ^, &, *, {, }, <, >, =, _, +,
-, $, /, (, ), \, ;, : , [, ], ‘, “, ?, ., !, |.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


29 Module-1: Introduction to C

4. White space characters: These characters are used to print a blank space on
the screen like \b, \t, \v, \r, \f, \n.
5. Escape sequences.

Keywords
• C has a set of 32 reserved words often known as keywords.
• All keywords are basically a sequence of characters that have a fixed meaning.
• By convention all keywords must be written in lowercase (small) letters.
• The keywords are for, while, do-while, auto break, case, char, continue, do,
double, else, enum, extern, float, goto, if, int, long, register, return, short,
signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile.

Keywords in C

Identifiers
Identifiers are names given to program elements such as variables, arrays and
functions.
Rules for forming identifier name
1. It cannot include any special characters or punctuation marks (like #, $, ^,
?, ., etc) except the underscore"_".
2. There cannot be two successive underscores
3. Keywords cannot be used as identifiers
4. The names are case sensitive. So, example, “FIRST” is different from “first”
and “First”.
5. It must begin with an alphabet or an underscore.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


30 Module-1: Introduction to C

It can be of any reasonable length. Though it should not contain more than 31
characters.
Example: roll_number, marks, name, emp_number, basic_pay, HRA, DA,
dept_code, a , sum, temp.

Basic data types in C

DATA TYPE SIZE IN BYTES RANGE

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


31 Module-1: Introduction to C

Variables
• A variable is defined as a meaningful name given to the data storage location
in computer memory.
• When using a variable, we actually refer to address of the memory where the
data is stored. C language supports two basic kinds of variables.

• Numeric variables can be used to store either integer values or floating point
values.
• While an integer value is a whole numbers without a fraction part or decimal
point, a floating point number, can have a decimal point in them.
• Numeric values may also be associated with modifiers like short, long, signed
and unsigned.
• By default, C automatically a numeric variable signed..

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


32 Module-1: Introduction to C

• Character variables can include any letter from the alphabet or from the
ASCII chart and numbers 0 – 9 that are put between single quotes.

Declaring Variables
• To declare a variable specify data type of the variable followed by its name.
• Variable names should always be meaningful and must reflect the purpose of
their usage in the program.
• Variable declaration always ends with a semicolon. Example,
int emp_num;
float salary;
char grade;
double balance_amount;
unsigned short int acc_no;

Initializing Variables
• Assigning a value to a variable is called variable initialization.
• The syntax is variable_name=value; Initialization can be done in two ways:-
1. We can assign an initial value to a variable within the declaration part itself
called static initialization.
Ex:- int a=10;, float x=100.0000;
2. We can assign an initial value to a variable during the program execution
called dynamic initialization.
Ex:- printf(Enter a value to a”);
scanf(“%d”, &a);

Constants
• Constants are identifiers whose value does not change.
• Constants are used to define fixed values like PI or the charge on an electron
so that their value does not get changed in the program even by mistake.
• There are mainly four types of constants in C:
1.Integer constants
2.Floating-point constants
3.Character constants
4.String constants
To declare a constant, precede the normal variable declaration with const
keyword and assign it a value. For example,
• const float pi = 3.14;
Another way to designate a constant is to use the pre-processor command
define.
• #define PI 3.14159

1. The integer constants: represents a whole number.


Ex:- 10, -200, -3456.
2. The floating-point constants:-represents a number that has a decimal
point.
Ex:- - 250.01, 67.73234.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


33 Module-1: Introduction to C

3. The character constants: represents a single character enclosed within a


pair of single quotes.
Ex.:- ‘s’, ‘%’, ‘7’.
4. The string constants:-represents a sequence of characters enclosed within
a pair of double quotes.
Ex:- “Hello”, “z”.

Declaring Constants
Rules that need to be applied to a #define statement which defines a constant.
Rule 1: Constant names are usually written in capital letters to visually
distinguish them from other variable names which are normally written in
lower case characters. Note that this is just a convention and not a rule.
Rule 2: No blank spaces are permitted in between the # symbol and define
keyword
Rule 3: Blank space must be used between #define and constant name and
between
constant name and constant value
Rule 4: #define is a pre-processor compiler directive and not a statement.
Therefore, it does not end with a semi-colon.

Input/Output statements in C

There are two types of Input and Output functions. They are,
1. Formatted I/O functions.
2. Unformatted I/O functions.
Formatted I/O functions enables the user to specify the type of the data and
the way in which it should be read in or written out.
Ex: Formatted input function- scanf()
Formatted output function- printf()

1.1 Formatted Input:


C provides a function scanf() to read the values for the variables in a C program
from the keyboard.
The scanf() function used to read numeric, character and string type of data.
It is included in the header file <stdio.h> .
The general format or syntax of scanf(),
scanf(“controlled string”,address_list);
where,
controlled string -> it is a sequence of one or more character group. Each is
character group is a combination of the % symbol and one of the conversion
characters. The control string specifies the type of the values which are to be
supplied to the variables.
Address_list -> it specifies the address of the memory locations where the
values of input variables should be stored.

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


34 Module-1: Introduction to C

Rules:
1. The controlled string must be enclosed within a pair of double quotes.
2. For every input variable, there must be one character group.
3. Each character group should begin with a % symbol and followed by a
conversion character.
4. Multiple number of character groups can be allowed within the control
string, in such case they may be contiguous or separated by blank space.
5. The address_list contains addresses of input variables.
6. Each input variable in the address list must be proceeded by an ampersand
(&). Ex. &a,&b. for string input variable & is not compulsory.
7. All the address list variables are separated by commas. Do not use blank
spaces.
8. The address list is not enclosed within double quotes.
9. The values for the address list variables should match in number, type and
order of the variables.
10. There must be a comma to separate control string and the address list.

Examples:
1. scanf(“%d %f %d”,&x,&y,&z);
2. scanf(“%d %c %d”,&a,&ch,&b);
3. scanf(“%f %c %f”,&x,&ch,&z);
4. scanf(“%d %s”,&number,name);
5. scanf(“%f %f”,&fval1,&fval2);
6. scanf(“%c %s”,&ch,str);

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


35 Module-1: Introduction to C

1.2 Formatted output:


C provides the printf() function to display the data on the standard output
device (monitor). The printf() function is included in the header file <stdio.h> .
The general form or syntax of the printf() function is,
printf(“control string”, variable_ list);
where,
control string -> specifies the type and format of the values to be displayed.
variable_list -> is a list of variables to be displayed on the monitor.

Example of printf()
1. printf(“ well come to c program”);
2. printf(“%d”, number);
3. printf(“%f %d”, fval,number);
4. printf(“sum of two number = %d”, sum);
5. printf(“%s, is a input string”, str);
6. printf(“x = %d and y = %d”, x,y);

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


36 Module-1: Introduction to C

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha


37 Module-1: Introduction to C

Unformatted Input output Functions:

The unformatted Input output function do not specify the types of data and the
way it should be read or written.
The unformatted input output functions only operates on character and string
type of data.

Unformatted input functions:

getchar() : unformatted input function to read a single character.


Syntax:
char_var= getchar();
ex: char ch;
ch=getchar();

gets() : unformatted input function to read a string.


Syntax:
gets(string);
ex: char name[10];
gets(name);

Unformatted output functions:

putchar() : unformatted output function which is used print single character.


Syntax:
putchar(ch_variable);
ex: char ch=’a’;
putchar(ch);

puts() : unformatted output function used to print string.


Syntax:
puts(String_variable);
ex: char name[10]=”abc”;
puts(name);

Dept. of CSE, AITM By: Prof. Mugdha and Prof. Shradha

You might also like