C Programming Unit-1 PPT
C Programming Unit-1 PPT
ng in C
U23CSTC01
Syllabus:
Computer:
A computer is a machine that can be programmed to carry out
sequences of arithmetic or logical operations (computation)
automatically.
• Modern digital electronic computers can perform generic sets of
operations known as programs. These programs enable computers to
perform a wide range of tasks.
• The term computer system may refer to a nominally complete
computer that includes the hardware, operating system, software,
and peripheral equipment needed and used for full operation; or to a
group of computers that are linked and function together, such as a
computer network or computer cluster.
• A broad range of industrial and consumer products use computers as
control systems.
• Computers power the Internet, which links billions of computers and
users.
• Early computers were meant to be used only for calculations. Simple
manual instruments like the abacus have aided people in doing
calculations since ancient times.
• The first digital electronic calculating machines were developed during
World War II, both electromechanical and using thermionic valves.
• The first semiconductor transistors in the late 1940s were followed by
the silicon-based MOSFET (MOS transistor) and monolithic integrated
circuit chip technologies in the late 1950s, leading to the
microprocessor and the microcomputer revolution in the 1970s.
• The speed, power and versatility of computers have been increasing
dramatically ever since then, with transistor counts increasing at a
rapid pace (Moore's law noted that counts doubled every two years),
leading to the Digital Revolution during the late 20th to early 21st
centuries.
• Conventionally, a modern computer consists of at least one
processing element, typically a central processing unit (CPU) in the
form of a microprocessor, together with some type of computer
memory, typically semiconductor memory chips.
• The processing element carries out arithmetic and logical operations,
and a sequencing and control unit can change the order of operations
in response to stored information.
• Peripheral devices include input devices (keyboards, mice, joystick,
etc.), output devices (monitor screens, printers, etc.), and
input/output devices that perform both functions (e.g., the 2000s-era
touchscreen).
• Peripheral devices allow information to be retrieved from an external
source and they enable the result of operations to be saved and
retrieved.
Below are the 8 Mechanical Calculators before modern computers
were invented:
• Abacus (ca. 2700 BC)
• Pascal’s Calculator (1652)
• Stepped Reckoner (1694)
• Arithmometer (1820)
• Comptometer (1887) and Comptograph (1889)
• The Difference Engine (1822)
• Analytical Engine (1834)
• The Millionaire (1893)
Basic terms:
• Vacuum tube – an electronic device that controls the flow of electrons
in a vacuum. It used as a switch, amplifier, or display screen in many
older model radios, televisions, computers, etc.
• a. Analog Computers:
• Process data that is continuous and not discrete.
• Used for tasks such as measuring and controlling physical quantities like
voltage, pressure, etc.
• b. Digital Computers:
• Work with discrete data.
• Use binary digits (bits) to process data.
• c. Hybrid Computers:
• Combine features of both analog and digital computers.
• Can process both continuous and discrete data.
Based on Size
• a. Supercomputers:
• The most powerful in terms of processing capacity.
• Used for complex scientific calculations, weather forecasting, molecular modeling, etc.
• b. Mainframe Computers:
• Large and powerful machines capable of handling and processing huge amounts of data rapidly.
• Often used by large organizations for bulk data processing like census, industry and consumer
statistics, etc.
• c. Minicomputers (Midrange Computers):
• Smaller and less powerful than mainframes.
• Serve as network servers and internet servers.
• d. Microcomputers (Personal Computers):
• Widely used by individuals and businesses.
• Includes desktop computers, laptops, tablets, and smartphones.
Based on Purpose
• a. General-purpose Computers:
• Designed to perform a range of tasks.
• Can run various types of software applications.
• b. Special-purpose Computers:
• Built for a specific task.
• Often found in industrial machines, medical equipment, and
scientific instruments.
Block Diagram of Computer:
Data → Input Units
(Keyboard/Mouse etc.) →
Central Processing Unit
(CPU) → Output Unit
(Monitor, Speaker,
Printer).
Steps Involved:
• Step 1: Input devices allow the users to provide data and commands to the computer. The data
inserted manually is collected by input devices like keyboard, mouse, scanners, and others. These
devices generate electrical signals or data packets representing the input.
• Step 2: The data generated by input devices is sent to the computer’s input interface/Memory
Unit which processes and formats the data for further use by the computer.
• Step 3: The processed input data is then sent to the computer’s Central Processing Unit (CPU)
which temporarily stores this data in memory (RAM) for immediate processing. The CPU executes
instructions related to the input data.
• For example, if you’re typing a document, the Central Processing Unit (CPU) processes the
keystrokes and stores them in memory. The control unit schedules all the activities for the smooth
working of the computer.
• Step 4: After processing, the CPU sends the results or instructions to the computer’s output
interface where the data is formatted for transmission to the output devices.
• Step 5: Then the output unit receives the final processed output. Output devices such as monitors,
printers, speakers, and others receive the formatted data. Monitors display visual information,
printers produce hard copies, and speakers play audio, based on the data they receive.
Input Unit:
• The input unit takes all the data received by the computer. The input unit
comprises different devices such as a mouse, keyboard, scanner, etc. All of these
devices act as intermediaries between the users and the computer.
• The input unit takes the data that has to be processed.
• The raw data is accepted by the computer in binary form. This data is then
processed and the desired output is produced.
• The Central Processing Unit or CPU is known as the brain of the computer. Just like the
human brain controls all human activities, the CPU also takes care of all the tasks.
• The CPU is responsible for performing all the arithmetic and logical operations within the
computer.
• All the major calculations, operations, and comparisons are performed inside the CPU.
Application Software:
• General Purpose Software
• Customize Software
• Utility Software
System Software:
• System software is software that directly operates the computer
hardware and provides the basic functionality to the users as well as
to the other software to operate smoothly.
• Or in other words, system software basically controls a computer’s
internal functioning and also controls hardware devices such as
monitors, printers, and storage devices, etc.
• It is like an interface between hardware and user applications, it helps
them to communicate with each other because hardware
understands machine language(i.e. 1 or 0) whereas user applications
are work in human-readable languages like English, Hindi, German,
etc. so system software converts the human-readable language into
machine language and vice versa.
Types of System Software:
It has two subtypes which are:
• Operating System: It is the main program of a computer system.
When the computer system ON it is the first software that loads into
the computer’s memory. Basically, it manages all the resources such
as computer memory, CPU, printer, hard disk, etc., and provides an
interface to the user, which helps the user to interact with the
computer system.
• It also provides various services to other computer software.
Examples of operating systems are Linux, Apple macOS, Microsoft
Windows, etc.
Language Processor:
• As we know that system software converts the human-readable
language into a machine language and vice versa. So, the conversion
is done by the language processor.
• It converts programs written in high-level programming languages like
Java, C, C++, Python, etc (known as source code), into sets of
instructions that are easily readable by machines (known as object
code or machine code).
Device Driver:
• A device driver is a program or software that controls a device and
helps that device to perform its functions. Every device like a printer,
mouse, modem, etc. needs a driver to connect with the computer
system eternally.
• So, when you connect a new device with your computer system, first
you need to install the driver of that device so that your operating
system knows how to control or manage that device.
Features of System Software:
• System Software is closer to the computer system.
• System Software is written in a low-level language in general.
• System software is difficult to design and understand.
• System software is fast in speed(working speed).
• System software is less interactive for the users in comparison to
application software.
Application Software:
• Software that performs special functions or provides functions that
are much more than the basic operation of the computer is known as
application software.
• Or in other words, application software is designed to perform a
specific task for end-users. It is a product or a program that is
designed only to fulfill end-users’ requirements.
• It includes word processors, spreadsheets, database management,
inventory, payroll programs, etc.
Types of Application Software:
There are different types of application software and those are:
• General Purpose Software: This type of application software is used
for a variety of task and it is not limited to performing a specific task
only. For example, MS-Word, MS-Excel, PowerPoint, etc.
• Customized Software: This type of application software is used or
designed to perform specific tasks or functions or designed for
specific organizations. For example, railway reservation system, airline
reservation system, invoice management system, etc.
• Utility Software: This type of application software is used to support
the computer infrastructure. It is designed to analyze, configure,
optimize and maintains the system, and take care of its requirements
as well. For example, antivirus, disk fragmenter, memory tester, disk
repair, disk cleaners, registry cleaners, disk space analyzer, etc.
Features of Application Software:
• An important feature of application software is it performs more
specialized tasks like word processing, spreadsheets, email, etc.
• Mostly, the size of the software is big, so it requires more storage
space.
• Application software is more interactive for the users, so it is easy to
use and design.
• The application software is easy to design and understand.
• Application software is written in a high-level language in general.
System Software Application Software
It is designed to manage the resources of the It is designed to fulfill the requirements of the
computer system, like memory and process user for performing specific tasks.
management, etc.
Less interactive for the users. More interactive for the users.
System software plays vital role for the effective Application software is not so important for the
functioning of a system. functioning of the system, as it is task specific.
Recursive Algorithm:
• A recursive algorithm is based on recursion. In this case, a problem is
broken into several sub-parts and called the same function again and
again.
Backtracking Algorithm:
• The backtracking algorithm builds the solution by searching among all
possible solutions. Using this algorithm, we keep on building the
solution following criteria. Whenever a solution fails we trace back to
the failure point build on the next solution and continue this process
till we find the solution or all possible solutions are looked after.
Searching Algorithm:
• Searching algorithms are the ones that are used for searching
elements or groups of elements from a particular data structure. They
can be of different types based on their approach or the data
structure in which the element should be found.
Sorting Algorithm:
• Sorting is arranging a group of data in a particular manner according
to the requirement. The algorithms which help in performing this
function are called sorting algorithms. Generally sorting algorithms
are used to sort groups of data in an increasing or decreasing manner.
Hashing Algorithm:
• Hashing algorithms work similarly to the searching algorithm. But
they contain an index with a key ID. In hashing, a key is assigned to
specific data.
How to Design an Algorithm?
• The problem that is to be solved by this algorithm i.e. clear problem
definition.
• The constraints of the problem must be considered while solving the
problem.
• The input to be taken to solve the problem.
• The output is to be expected when the problem is solved.
• The solution to this problem is within the given constraints.
Algorithm to add 3 numbers and print their sum:
• START
• Declare 3 integer variables num1, num2, and num3.
• Take the three numbers, to be added, as inputs in variables num1,
num2, and num3 respectively.
• Declare an integer variable sum to store the resultant sum of the 3
numbers.
• Add the 3 numbers and store the result in the variable sum.
• Print the value of the variable sum
• END
// C program to add three numbers printf("Enter the 2nd number: ");
// with the help of above designed scanf("%d", &num2);
algorithm
printf("%d\n", num2);
printf("Enter the 3rd number: ");
#include <stdio.h>
int main() scanf("%d", &num3);
{ printf("%d\n", num3);
// Variables to take the input of the 3 // Calculate the sum using + operator
numbers // and store it in variable sum
int num1, num2, num3; sum = num1 + num2 + num3;
// Variable to store the resultant sum // Print the sum
int sum;
printf("\nSum of the 3 numbers is:
// Take the 3 numbers as input %d", sum);
printf("Enter the 1st number: ");
return 0;
scanf("%d", &num1);
}
printf("%d\n", num1);
Flow chart:
A flowchart is a type of diagram that represents a
workflow or process. A flowchart can also be defined as a
diagrammatic representation of an algorithm, a step-by-
step approach to solving a task.
Flow chart symbol:
Uses of Flowcharts:
• Process flowchart: This type of flowchart shows all the activities that
are involved in making a product. It provides a pathway to analyze the
product to be built. A process flowchart is most commonly used in
process engineering to illustrate the relation between the major as well
as minor components present in the product. It is used in business
product modeling to help understand employees about the project
requirements and gain some insight into the project.
• Data flowchart: As the name suggests, the data flowchart is used to
analyze the data, specifically it helps in analyzing the structural details
related to the project. Using this flowchart, one can easily understand
the data inflow and outflow from the system. It is most commonly used
to manage data or to analyze information to and fro from the system.
• Business Process Modeling Diagram: Using this flowchart or diagram,
one can analytically represent the business process and help simplify
the concepts needed to understand business activities and the flow of
information. This flowchart illustrates the business process and
models graphically which paves the way for process improvement.
Types of boxes used to make a flowchart:
• Terminal
• This box is of an oval shape which is used to indicate the start or end
of the program. Every flowchart diagram has an oval shape that
depicts the start of an algorithm and another oval shape that depicts
the end of an algorithm.
• Data
• 1. Start
• 2. Put input a
• 3. Now check the
condition if a % 2 == 0,
goto step 5. Else goto step
4
• 4. Now print(“number is
odd”) and goto step 6
• 5. Print(“number is even”)
• 6. Stop
• Algorithm:
• 1. Start
• 2. Input number a
• 3. Now initialise c = 1
• 4. Now we check the
condition if c <= 5,
goto step 5 else, goto
step 7.
• 5. Print a
• 6. c = c + 1 and goto
step 4
• 7. Stop
• Algorithm:
• 1. Start
• 2. Now initialise c = 1
• 3. Now we check the
condition if c < 11,
then goto step 4
otherwise goto step 6.
• 4. Print c
• 5. c = c + 1 then goto
step 3
• 6. Stop
Number system:
Binary System: Binary System is the system of writing
number using only two numbers that are, 0 and 1. The
base of binary number is 2.