Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
57 views49 pages

Unit 1

notes of pproblem solving in c ist year

Uploaded by

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

Unit 1

notes of pproblem solving in c ist year

Uploaded by

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

Unit 1

Introduction to Computer Systems: Introduction to computer, Description of block


diagram of computer
What is Computer?
What is Computer : Computer is an electronic device that is designed to work
with Information. The term computer is derived from the Latin term ‘computare’, this means
to calculate or programmable machine. Computer can not do anything without a Program. It
represents the decimal numbers through a string of binary digits. The Word ‘Computer’ usually
refers to the Center Processor Unit plus Internal memory.
Charles Babbage is called the “Grand Father” of the computer. The First mechanical computer
designed by Charles Babbage was called Analytical Engine. It uses read-only memory in the
form of punch cards.
The computer is an electronic device that takes input from the user and processes these data
under the control of a set of instructions (called program) and gives the result (output) and saves
future use. It can process both numerical and non-numerical (arithmetic and logical) calculations.

Digital Computer Definition


The basic components of a modern digital computer are: Input Device, Output Device, Central
Processor Unit (CPU), mass storage device and memory. A Typical modern computer uses LSI
Chips. Four Functions about computer are:
Accepts data Input
Processes data Processing
Produces output
Output
Stores results Storage

Input (Data):
Input is the raw information entered into a computer from the input devices. It is the collection of
letters, numbers, images etc.
Process:
Process is the operation of data as per given instruction. It is totally internal process of the
computer system.
Output:
Output is the processed data given by computer after data processing. Output is also called as
Result. We can save these results in the storage devices for the future use.
Computer Classification: By Size and Power
Computers differ based on their data processing abilities. They are classified according to
purpose, data handling and functionality.
According to functionality, computers are classified as:

• Analog Computer: A computer that represents numbers by some continuously variable physical
quantity, whose variations mimic some system’s properties being modeled.
• Personal computer: A personal computer is a computer small and low cost. The term”personal
computer” is used to describe desktop computers.
• Workstation: A terminal or desktop computer in a network. In this context, the workstation is
just a generic term for a user’s machine (client machine) in contrast to a “server” or
“mainframe.”
• Minicomputer: A minicomputer isn’t very mini. At least, not in the way most of us think of
mini. You know how big your personal computer is and its related family.
• Mainframe: It refers to the kind of large computer that runs an entire corporation.
• Supercomputer: It is the most giant, fastest, and most expensive computers on earth.
• Microcomputer: Your personal computer is a microcomputer.

Definition of Computer | Meaning of computer

In 1640s, Computer term was first used as “one who calculates.” From 1897, term changed
and got a new computer meaning “Calculating machine“. From 1945 the term indicates as
“programmable digital electronic computer“.

Computer Definition
The word compute is derived from the Latin word ‘computare’, was meaning “arithmetic,
accounting”.
The Computer meaning is the digital device that stores information in memory using input
devices and manipulate information to produce output according to given instructions.
The actual machinery, the physical parts of a computer system refer to as Computer hardware;
the instruction (a program) that tells the computer what to do or how to do, that is
called Computer software (often called just software).
Computer Meaning in general term

Technically, a computer means to calculate or electronic programmable machine.


Computer is used to perform some sequence of instructions in fast and accurate manner.
Computer receives input in the form of digitized data, using input devices like keyboard, mouse,
joystick, scanner etc. It process based on a program instructions to give output.

Two Different form of computer are exited: analog and digital computer

• An analog computer or ‘analogue computer’ which is used to process analog data.


• Today most commonly type of computer that input information using discrete rather than
continuous, is called digital computer that use ‘binary digits’.

Generally following Computer hardware components are required

• Memory: It is a physical device (integrated circuits or chip) that enables a computer to store
data and programs tSsemporarily or permanently. It is also term as “primary storage”.
• Mass storage device (MSD): It is used to store large amounts of data for example hard disks,
USB drive, CD-ROM etc.
• Input device: It is any hardware device like keyboard and mouse that sends data to a computer.
• Output device: It is a device that sends data from a computer to another device.
• CPU (Central Processing Unit): It is also referred to as a processor or brains of a computer
that carries out the instructions of a computer system.

History of Computer

Professor Charles Babbage’s analytical engine considered as “fundamental framework of


computer” is a mechanical general-purpose programmable computing engine. It was a successor
to the Difference Engine.
Computer that we use today is absolutely different from the first generation computer. Evolution
in technology from 19th century to present day modified computer totally.

Uses of Computer

In digital world, from a small wrist watch to space satellite all are controlled by computer. A
small or large machine was handled by humans in past, but in digitalized world these are handled
by programmed humans i.e. ‘Robots’.

Types of Computer, By Size

According to required services speed or efficiency different types of computers are available in
market.
• Super Computer: Large in size and more powerful. Used for large and complex calculation.
• Mainframe Computer: Mainframe computers are smaller than supercomputer. It has large
storage capacity and capable to perform large calculation. Used in bank, educational institution.
• Minicomputer: Minicomputers are multi user which are mainly used by small organization
• Microcomputer: Microcomputer is defined as small size, inexpensive, easy to carry computer
e.g. Laptop, tablets.

A computer can process data, pictures, sound and graphics. They can solve highly complicated
problems quickly and accurately. A computer as shown in Fig. performs basically five major
computer operations or functions irrespective of their size and make. These are

1) it accepts data or instructions by way of input,


2) it stores data,
3) it can process data as required by the user,
4) it gives results in the form of output, and
5) it controls all operations inside a computer.

We discuss below each of these Computer operation


Fig 1.1 Block Diagram of computer system

Block Diagram of Computer and Explain its Various Components


1. Input: This is the process of entering data and programs in to the computer system. You
should know that computer is an electronic machine like any other machine which takes as
inputs raw data and performs some processing giving out processed data. Therefore, the input
unit takes data from us to the computer in an organized manner for processing.
2. Storage: The process of saving data and instructions permanently is known as storage. Data
has to be fed into the system before the actual processing starts. It is because the processing
speed of Central Processing Unit (CPU) is so fast that the data has to be provided to CPU with
the same speed. Therefore the data is first stored in the storage unit for faster access and
processing. This storage unit or the primary storage of the computer system is designed to do the
above functionality. It provides space for storing data and instructions.

The storage unit performs the following major functions:


• All data and instructions are stored here before and after processing.
• Intermediate results of processing are also stored here.

3. Processing: The task of performing operations like arithmetic and logical operations is called
processing. The Central Processing Unit (CPU) takes data and instructions from the storage unit
and makes all sorts of calculations based on the instructions given and the type of data provided.
It is then sent back to the storage unit.
4. Output: This is the process of producing results from the data for getting useful information.
Similarly the output produced by the computer after processing must also be kept somewhere
inside the computer before being given to you in human readable form. Again the output is also
stored inside the computer for further processing.
5. Control: The manner how instructions are executed and the above operations are performed.
Controlling of all operations like input, processing and output are performed by control unit. It
takes care of step by step processing of all operations inside the computer.

Functional Units
In order to carry out the operations mentioned in the previous section the computer allocates the
task between its various functional units. The computer system is divided into three separate
units for its operation. They are
Arithmetic Logical Unit (ALU)
Logical Unit :After you enter data through the input device it is stored in the primary storage
unit. The actual processing of the data and instruction are performed by Arithmetic Logical Unit.
The major operations performed by the ALU are addition, subtraction, multiplication, division,
logic and comparison. Data is transferred to ALU from storage unit when required. After
processing the output is returned back to storage unit for further processing or getting stored.

Control Unit (CU)


The next component of computer is the Control Unit, which acts like the supervisor seeing that
things are done in proper fashion. Control Unit is responsible for coordinating various
operations using time signal. The control unit determines the sequence in which computer
programs and instructions are executed. Things like processing of programs stored in the main
memory, interpretation of the instructions and issuing of signals for other units of the computer
to execute them. It also acts as a switch board operator when several users access the computer
simultaneously. Thereby it coordinates the activities of computer’s peripheral equipment as they
perform the input and output.
Central Processing Unit (CPU)
The ALU and the CU of a computer system are jointly known as the central processing unit. You
may call CPU as the brain of any computer system. It is just like brain that takes all major
decisions, makes all sorts of calculations and directs different parts of the computer functions by
activating and controlling the operations.

Application and utility software:


1. Application Software :
Application Software, as name suggests, is a software designed to help people with
information technology and make users more productive or assist them with personal tasks. It
is used to perform personal and business functions and its main purpose is to meet user
requirements.
Example : VLC media player, Microsoft Word processor, Google chrome, accounting
applications, photo editor, etc.
2. Utility Software :
Utility Software, as name suggests, is a software designed to perform particular tasks that help
in making device perform better and keep environment safe. It assists users with controlling
and maintaining operations of computer, hardware, software, or its devices. It also provides
energy and power to different site processes.
Example : AVAST antivirus, disk tools, backup software, etc.
Difference between Application Software and Utility Software :
S. Basis of
No. Comparison Application Software Utility Software

It refers to software programs


It refers to a computer program that
that add functionality to a
1. Definition performs particular functions for
computer and help to perform
end-users.
in a better way.

It helps to analyze, configure,


It deals with user inputs and helps
2. Supports optimize or maintain a
user to complete their task.
computer system.

It mainly focuses on how


It mainly focuses on the work of a computer infrastructure such
3. Focus
user or an organization. as hardware, operating system,
software, etc., operates.

It can be downloaded either


It can be downloaded from the
4. Download from the web or comes pre-
internet.
installed.

It requires more space and more It requires less space and less
power on the computer due to its power due to its smaller size as
5. Space
bigger size as compared to utility compared to application
software. software.

6. Functionality This software is designed to This software is designed to


perform a group of coordinated perform maintenance tasks on
S. Basis of
No. Comparison Application Software Utility Software

the computer systems so that


functions, activities, or tasks that
system can perform better and
are beneficial for end-users.
smoothly.

This software help in


This software help people to executing several crucial tasks
Variety of
7. perform activity, mitigate issues, for the operating system helps
Tasks
manipulate text, number, audio, etc. in the overall maintenance of
the system, etc.

It also helps the user to


It also helps to lower IT costs,
control, manage, and maintain
improve employee productivity,
the computer’s operating
lower customer churn, meet the
8. Supports User system, defragment hard disk
exact needs of the user, make
to correct and fix the problems
business activities more efficient,
in it, scan viruses, clean the
facilitate communications, etc.
disk, etc.

It can be either free or paid if It is mostly free to install on


9. Price
downloaded from the web. the computer.

10. Size It is of big size. It is of small size.

It is like an add-on that may or may It always demonstrates an


11. Usage
not be beneficial. interest in the device.

12. Example Graphic Designing Softwares Antivirus Softwares

Number Systems, Decimal, Binary, Hex, Octal


In mathematics, a “base” or a “radix” is the number of different digits or combination of digits and
letters that a system of counting uses to represent numbers.
For example,

 Base 10 (Decimal) — Represent any number using 10 digits [0–9]

 Base 2 (Binary) — Represent any number using 2 digits [0–1]

 Base 8 (Octal) — Represent any number using 8 digits [0–7]

 Base 16(Hexadecimal) — Represent any number using 10 digits and 6 characters [0–
9, A, B, C, D, E, F]

In any of the number systems mentioned above, zero is very important as a place-holding value.

Take the number 1005. How do we write that number so that we know that there are no tens and

hundreds in the number? We can’t write it as 15 because that’s a different number and how do we

write a million (1,000,000) or a billion (1,000,000,000) without zeros? Do you realize it’s

significance?

First, we will see how the decimal number system is been built, and then we will use the same

rules on the other number systems as well.

So how do we build a number system?

We all know how to write numbers up to 9, don’t we? What then? Well, it’s simple really. When

you have used up all of your symbols, what you do is,

 you add another digit to the left and make the right digit 0.

 Then again go up to until you finish up all your symbols on the right side and when

you hit the last symbol increase the digit on the left by 1.
 When you used up all the symbols on both the right and left digit, then make both of

them 0 and add another 1 to the left and it goes on and on like that.

If you use the above 3 rules on a decimal system,

 Write numbers 0–9.

 Once you reach 9, make rightmost digit 0 and add 1 to the left which means 10.

 Then on right digit, we go up until 9 and when we reach 19 we use 0 on the right digit

and add 1 to the left, so we get 20.

 Likewise, when we reach 99, we use 0s in both of these digits’ places and add 1 to the

left which gives us 100.

So you see when we have ten different symbols, when we add digits to the left side of a number,

each position is going to worth 10 times more than it’s previous one.

How to read numbers?

Let’s take the same decimal number system. There are only two rules actually.
 You have a symbol to represent a quantity [0–9]

 Then the meaning of a digit based on its position — let’s get this clarified a bit.

Let’s take one digit number ‘8’. This simply means 8, in other words, it is exactly what it says it

represents. What about 24? In case of two digits, right digit says what it means, but left digit

means ten times what it says. That is, 4 is 4, 2 is 20. Altogether forms 24.

If we take a three digit number, rightmost digit means what it says, the middle one is ten times

what it says, leftmost digit 100 times what it says. Simply if we take number 546, it means 6 + (10

* 4) + (5 * 100) = 546.

Binary

With binary, we have only two digits to represent a number, 0 and 1 and we are already out of

symbols. So what do we do? Let’s apply the same rules that we used on the decimal system.

We make the right digit 0 and add 1 to left, that is, our next number is ‘10’. Then we go up until

we used up all our symbols on the right side.So the next number in line is 11.
After ‘11’, we put 0s in both these places and add 1 to the left and we get 100.

Then 101, 110, 111 then 1000 …

This binary number system is based on two digits and each position is worth two times more than

the previous position.

Reading a binary number is almost same as reading a decimal. Right digit says what it means,

next one means two times the previous one, after that 4 times etc…

So 101 means 5 in decimal.

These same rules apply to octal and hexadecimal number systems as well. With octal, we have

only 8 digits to represent numbers so once we get to 7 the next number is 10 and in hexadecimal,

we have 10 digits and 6 letters to represent numbers. In that case, when we reach 9 next number is

represented in the letter ‘A’. Next one ‘B’. Likewise, we go up to letter ‘F’ and after ‘F’ comes

‘10’.
I’ll just list down few numbers in these 4 different number systems and see whether you can apply

the rules that we discussed above to get the next number.

Introduction to flowchart:
What is a Flowchart?
Flowchart is a graphical representation of an algorithm. Programmers often use it as a
program-planning tool to solve a problem. It makes use of symbols which are connected
among them to indicate the flow of information and processing.
The process of drawing a flowchart for an algorithm is known as “flowcharting”.
Basic Symbols used in Flowchart Designs
1. Terminal: The oval symbol indicates Start, Stop and Halt in a program’s logic
flow. A pause/halt is generally used in a program logic under some error conditions.
Terminal is the first and last symbols in the flowchart.

 Input/Output: A parallelogram denotes any function of input/output type. Program


instructions that take input from input devices and display output on output devices
are indicated with parallelogram in a flowchart.

 Processing: A box represents arithmetic instructions. All arithmetic processes such


as adding, subtracting, multiplication and division are indicated by action or process
symbol.

 Decision Diamond symbol represents a decision point. Decision based operations


such as yes/no question or true/false are indicated by diamond in flowchart.

 Connectors: Whenever flowchart becomes complex or it spreads over more than


one page, it is useful to use connectors to avoid any confusions. It is represented by
a circle.

 Flow lines: Flow lines indicate the exact sequence in which instructions are
executed. Arrows represent the direction of flow of control and relationship among
different symbols of flowchart.

Rules For Creating Flowchart :


A flowchart is a graphical representation of an algorithm.it should follow some rules while
creating a flowchart
Rule 1: Flowchart opening statement must be ‘start’ keyword.
Rule 2: Flowchart ending statement must be ‘end’ keyword.
Rule 3: All symbols in the flowchart must be connected with an arrow line.
Rule 4: The decision symbol in the flowchart is associated with the arrow line.
Advantages of Flowchart:
 Flowcharts are a better way of communicating the logic of the system.
 Flowcharts act as a guide for blueprint during program designed.
 Flowcharts help in debugging process.
 With the help of flowcharts programs can be easily analyzed.
 It provides better documentation.
 Flowcharts serve as a good proper documentation.
 Easy to trace errors in the software.
 Easy to understand.
 The flowchart can be reused for inconvenience in the future.
 It helps to provide correct logic.

Disadvantages of Flowchart:
 It is difficult to draw flowcharts for large and complex programs.
 There is no standard to determine the amount of detail.
 Difficult to reproduce the flowcharts.
 It is very difficult to modify the Flowchart.
 Making a flowchart is costly.
 Some developer thinks that it is waste of time.
 It makes software processes low.
 If changes are done in software, then the flowchart must be redrawn

Example : Draw a flowchart to input two numbers from the user and display the largest
of two numbers
// C program to find largest of two numbers

#include <stdio.h>
int main()
{
int num1, num2, largest;
/*Input two numbers*/
printf("Enter two numbers:\n");
scanf("%d%d", &num1, &num2);
/*check if a is greater than b*/
if (num1 > num2)
largest = num1;
else
largest = num2;
/*Print the largest number*/
printf("%d", largest);
return 0;
}
Output
Enter two numbers:
10 30
30

Introduction to Algorithms:
Definition of Algorithm
The word Algorithm means ” A set of finite rules or instructions to be followed in
calculations or other problem-solving operations ”
Or
” A procedure for solving a mathematical problem in a finite number of steps that frequently
involves recursive operations”.
Therefore Algorithm refers to a sequence of finite steps to solve a particular problem.

Use of the Algorithms:


Algorithms play a crucial role in various fields and have many applications. Some of the key
areas where algorithms are used include:
1. Computer Science: Algorithms form the basis of computer programming and are
used to solve problems ranging from simple sorting and searching to complex tasks
such as artificial intelligence and machine learning.
2. Mathematics: Algorithms are used to solve mathematical problems, such as finding
the optimal solution to a system of linear equations or finding the shortest path in a
graph.
3. Operations Research: Algorithms are used to optimize and make decisions in
fields such as transportation, logistics, and resource allocation.
4. Artificial Intelligence: Algorithms are the foundation of artificial intelligence and
machine learning, and are used to develop intelligent systems that can perform tasks
such as image recognition, natural language processing, and decision-making.
5. Data Science: Algorithms are used to analyze, process, and extract insights from
large amounts of data in fields such as marketing, finance, and healthcare.
These are just a few examples of the many applications of algorithms. The use of algorithms is
continually expanding as new technologies and fields emerge, making it a vital component of
modern society.
What are the Characteristics of an Algorithm?

As one would not follow any written instructions to cook the recipe, but only the standard one.
Similarly, not all written instructions for programming are an algorithm. For some instructions
to be an algorithm, it must have the following characteristics:
 Clear and Unambiguous: The algorithm should be unambiguous. Each of its steps
should be clear in all aspects and must lead to only one meaning.
 Well-Defined Inputs: If an algorithm says to take inputs, it should be well-defined
inputs. It may or may not take input.
 Well-Defined Outputs: The algorithm must clearly define what output will be
yielded and it should be well-defined as well. It should produce at least 1 output.
 Finite-ness: The algorithm must be finite, i.e. it should terminate after a finite time.
Every instruction which contains a fundamental operator must be terminated within
a finite amount of time. Infinite loops or recursive functions without base conditions
do not possess finiteness.
 Feasible: The algorithm must be simple, generic, and practical, such that it can be
executed with the available resources. It must not contain some future technology or
anything.
 Language Independent: The Algorithm designed must be language-independent,
i.e. it must be just plain instructions that can be implemented in any language, and
yet the output will be the same, as expected.
 Input: An algorithm has zero or more inputs. Each that contains a fundamental
operator must accept zero or more inputs.
 Output: An algorithm produces at least one output. Every instruction that contains
a fundamental operator must accept zero or more inputs.
 Definiteness: All instructions in an algorithm must be unambiguous, precise, and
easy to interpret. By referring to any of the instructions in an algorithm one can
clearly understand what is to be done. Every fundamental operator in instruction
must be defined without any ambiguity.
 Effectiveness: An algorithm must be developed by using very basic, simple, and
feasible operations so that one can trace it out by using just paper and pencil.

Properties of Algorithm:
 It should terminate after a finite time.
 It should produce at least one output.
 It should take zero or more input.
 It should be deterministic means giving the same output for the same input case.
 Every step in the algorithm must be effective i.e. every step should do some work.

Types of Algorithms:
There are several types of algorithms available. Some important algorithms are:
1. Brute Force Algorithm:
It is the simplest approach to a problem. A brute force algorithm is the first approach that
comes to finding when we see a problem.
2. 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.

Here's a C example that calculates the factorial of a non-negative integer using recursion:

#include <stdio.h>

// Function to calculate the factorial of a number

int factorial(int n)

// Base case: factorial of 0 or 1 is 1

if (n == 0 || n == 1)

return 1;

// Recursive step: n! = n * (n-1)!

else

return n * factorial(n - 1);


}

int main() {

int num;

printf("Enter a non-negative integer: ");

scanf("%d", &num);

if (num < 0)

printf("Factorial is not defined for negative numbers.\n");

else

int result = factorial(num);

printf("Factorial of %d is %d\n", num, result);

return 0;
}

3. 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.
4. 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.
5. 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.
6. 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.
7. Divide and Conquer Algorithm :
This algorithm breaks a problem into sub-problems, solves a single sub-problem, and merges
the solutions to get the final solution. It consists of the following three steps:
 Divide
 Solve
 Combine
8. Greedy Algorithm:
In this type of algorithm, the solution is built part by part. The solution for the next part is built
based on the immediate benefit of the next part. The one solution that gives the most benefit
will be chosen as the solution for the next part.
9. Dynamic Programming Algorithm :
This algorithm uses the concept of using the already found solution to avoid repetitive
calculation of the same part of the problem. It divides the problem into smaller overlapping
subproblems and solves them.
10. Randomized Algorithm:
In the randomized algorithm, we use a random number so it gives immediate benefit. The
random number helps in deciding the expected outcome.

Advantages of Algorithms:
 It is easy to understand.
 An algorithm is a step-wise representation of a solution to a given problem.
 In an Algorithm the problem is broken down into smaller pieces or steps hence, it is
easier for the programmer to convert it into an actual program.
Disadvantages of Algorithms :
 Writing an algorithm takes a long time so it is time-consuming.
 Understanding complex logic through algorithms can be very difficult.
 Branching and Looping statements are difficult to show in Algorithms(imp).

How to Design an Algorithm?


To write an algorithm, the following things are needed as a pre-requisite:
1. The problem that is to be solved by this algorithm i.e. clear problem definition.
2. The constraints of the problem must be considered while solving the problem.
3. The input to be taken to solve the problem.
4. The output is to be expected when the problem is solved.
5. The solution to this problem is within the given constraints.
Then the algorithm is written with the help of the above parameters such that it solves the
problem.

Example: Consider the example to add three numbers and print the sum.
Step 1: Fulfilling the pre-requisites
As discussed above, to write an algorithm, its prerequisites must be fulfilled.
1. The problem that is to be solved by this algorithm: Add 3 numbers and print their
sum.
2. The constraints of the problem that must be considered while solving the
problem: The numbers must contain only digits and no other characters.
3. The input to be taken to solve the problem: The three numbers to be added.
4. The output to be expected when the problem is solved: The sum of the three
numbers taken as the input i.e. a single integer value.
5. The solution to this problem, in the given constraints: The solution consists of
adding the 3 numbers. It can be done with the help of the ‘+’ operator, or bit-wise,
or any other method.
Step 2: Designing the algorithm
Now let’s design the algorithm with the help of the above pre-requisites:
Algorithm to add 3 numbers and print their sum:
1. START
2. Declare 3 integer variables num1, num2, and num3.
3. Take the three numbers, to be added, as inputs in variables num1, num2, and num3
respectively.
4. Declare an integer variable sum to store the resultant sum of the 3 numbers.
5. Add the 3 numbers and store the result in the variable sum.
6. Print the value of the variable sum
7. END
Step 3: Testing the algorithm by implementing it.
To test the algorithm, let’s implement it in C language.
Program:
// C program to add three numbers
// with the help of above designed algorithm
#include <stdio.h>
int main()
{
// Variables to take the input of the 3 numbers
int num1, num2, num3;
// Variable to store the resultant sum
int sum;
// Take the 3 numbers as input
printf("Enter the 1st number: ");
scanf("%d", &num1);
printf("%d\n", num1);
printf("Enter the 2nd number: ");
scanf("%d", &num2);
printf("%d\n", num2);
printf("Enter the 3rd number: ");
scanf("%d", &num3);
printf("%d\n", num3);
// Calculate the sum using + operator
// and store it in variable sum
sum = num1 + num2 + num3;
// Print the sum
printf("\nSum of the 3 numbers is: %d", sum);
return 0;
}
Output
Enter the 1st number: 0
Enter the 2nd number: 0
Enter the 3rd number: -1577141152

Sum of the 3 numbers is: -1577141152


Here is the step-by-step algorithm of the code:
1. Declare three variables num1, num2, and num3 to store the three numbers to be
added.
2. Declare a variable sum to store the sum of the three numbers.
3. Use the cout statement to prompt the user to enter the first number.
4. Use the cin statement to read the first number and store it in num1.
5. Use the cout statement to prompt the user to enter the second number.
6. Use the cin statement to read the second number and store it in num2.
7. Use the cout statement to prompt the user to enter the third number.
8. Use the cin statement to read and store the third number in num3.
9. Calculate the sum of the three numbers using the + operator and store it in the sum
variable.
10. Use the cout statement to print the sum of the three numbers.
11. The main function returns 0, which indicates the successful execution of the
program.
Time complexity: O(1)
Auxiliary Space: O(1)

One problem, many solutions: The solution to an algorithm can be or cannot be more than
one. It means that while implementing the algorithm, there can be more than one method to
implement it. For example, in the above problem of adding 3 numbers, the sum can be
calculated in many ways:
 + operator
 Bit-wise operators
 . . etc

How to analyze an Algorithm?


For a standard algorithm to be good, it must be efficient. Hence the efficiency of an algorithm
must be checked and maintained. It can be in two stages:
1. Priori Analysis:
“Priori” means “before”. Hence Priori analysis means checking the algorithm before its
implementation. In this, the algorithm is checked when it is written in the form of theoretical
steps. This Efficiency of an algorithm is measured by assuming that all other factors, for
example, processor speed, are constant and have no effect on the implementation. This is done
usually by the algorithm designer. This analysis is independent of the type of hardware and
language of the compiler. It gives the approximate answers for the complexity of the program.
2. Posterior Analysis:
“Posterior” means “after”. Hence Posterior analysis means checking the algorithm after its
implementation. In this, the algorithm is checked by implementing it in any programming
language and executing it. This analysis helps to get the actual and real analysis report about
correctness(for every possible input/s if it shows/returns correct output or not), space required,
time consumed, etc. That is, it is dependent on the language of the compiler and the type of
hardware used.

What is Algorithm complexity and how to find it?


An algorithm is defined as complex based on the amount of Space and Time it consumes.
Hence the Complexity of an algorithm refers to the measure of the time that it will need to
execute and get the expected output, and the Space it will need to store all the data (input,
temporary data, and output). Hence these two factors define the efficiency of an algorithm.

The two factors of Algorithm Complexity are:


 Time Factor: Time is measured by counting the number of key operations such as
comparisons in the sorting algorithm.
 Space Factor: Space is measured by counting the maximum memory space
required by the algorithm to run/execute.

Therefore the complexity of an algorithm can be divided into two types:


1. Space Complexity: The space complexity of an algorithm refers to the amount of memory
required by the algorithm to store the variables and get the result. This can be for inputs,
temporary operations, or outputs.

How to calculate Space Complexity?


The space complexity of an algorithm is calculated by determining the following 2
components:

 Fixed Part: This refers to the space that is required by the algorithm. For example,
input variables, output variables, program size, etc.
 Variable Part: This refers to the space that can be different based on the
implementation of the algorithm. For example, temporary variables, dynamic
memory allocation, recursion stack space, etc.
Therefore Space complexity S(P) of any algorithm P is S(P) = C + SP(I), where C
is the fixed part and S(I) is the variable part of the algorithm, which depends on
instance characteristic I.

Example: Consider the below algorithm for Linear Search


Step 1: START
Step 2: Get n elements of the array in arr and the number to be searched in x
Step 3: Start from the leftmost element of arr[] and one by one compare x with each element of
arr[]
Step 4: If x matches with an element, Print True.
Step 5: If x doesn’t match with any of the elements, Print False.
Step 6: END
Here, There are 2 variables arr[], and x, where the arr[] is the variable part of n elements and
x is the fixed part. Hence S(P) = 1+n. So, the space complexity depends on n(number of
elements). Now, space depends on data types of given variables and constant types and it will
be multiplied accordingly.

2. Time Complexity: The time complexity of an algorithm refers to the amount of time
required by the algorithm to execute and get the result. This can be for normal operations,
conditional if-else statements, loop statements, etc.

How to Calculate, Time Complexity?


The time complexity of an algorithm is also calculated by determining the following 2
components:
 Constant time part: Any instruction that is executed just once comes in this part.
For example, input, output, if-else, switch, arithmetic operations, etc.
 Variable Time Part: Any instruction that is executed more than once, say n times,
comes in this part. For example, loops, recursion, etc.
Therefore Time complexity of any algorithm P is T(P) = C + TP(I), where C is the
constant time part and TP(I) is the variable part of the algorithm, which depends on
the instance characteristic I.
Example: In the algorithm of Linear Search above, the time complexity is calculated as
follows:
Step 1: –Constant Time
Step 2: — Variable Time (Taking n inputs)
Step 3: –Variable Time (Till the length of the Array (n) or the index of the found element)
Step 4: –Constant Time
Step 5: –Constant Time
Step 6: –Constant Time
Hence, T(P) = 1 + n + n(1 + 1) + 1 = 2 + 3n, which can be said as T(n).

How to express an Algorithm?


1. Natural Language:- Here we express the Algorithm in the natural English
language. It is too hard to understand the algorithm from it.
2. Flow Chart:- Here we express the Algorithm by making a graphical/pictorial
representation of it. It is easier to understand than Natural Language.
3. Pseudo Code:- Here we express the Algorithm in the form of annotations and
informative text written in plain English which is very much similar to the real code
but as it has no syntax like any of the programming languages, it can’t be compiled
or interpreted by the computer. It is the best way to express an algorithm because it
can be understood by even a layman with some school-level knowledge.
Introduction to C programming and Program structure
Example:
Line 1: #include <stdio.h>
Line 2: // blank Line
Line 3: int main()
{
Line 4: printf("Hello World!");
Line 5: return 0;
Line 6: }
Example explained
Line 1: #include <stdio.h> is a header file library that lets us work with input and output
functions, such as printf() (used in line 4). Header files add functionality to C programs.
Don't worry if you don't understand how #include <stdio.h> works. Just think of it as something
that (almost) always appears in your program.
Line 2: A blank line. C ignores white space. But we use it to make the code more readable.
Line 3: Another thing that always appear in a C program, is main(). This is called a function. Any
code inside its curly brackets {} will be executed.
Line 4: printf() is a function used to output/print text to the screen. In our example it will output
"Hello World!".
Note that: Every C statement ends with a semicolon ;
Note: The body of int main() could also been written as:
int main(){printf("Hello World!");return 0;}

Remember: The compiler ignores white spaces. However, multiple lines makes the code more
readable.
Line 5: return 0 ends the main() function.
Line 6: Do not forget to add the closing curly bracket } to actually end the main function.
C Variables:
Variables are containers for storing data values, like numbers and characters.
In C, there are different types of variables (defined with different keywords),
for example:
int - stores integers (whole numbers), without decimals, such as 123 or -123
float - stores floating point numbers, with decimals, such as 19.99 or -19.99
char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes

Declaring (Creating) Variables:


To create a variable, specify the type and assign it a value:

Syntax
type variableName = value;
Where type is one of C types (such as int), and variableName is the name of the variable (such as
x or myName). The equal sign is used to assign a value to the variable.

So, to create a variable that should store a number, look at the following example:
Example
Create a variable called myNum of type int and assign the value 15 to it:
int myNum = 15;

You can also declare a variable without assigning the value, and assign the value later:
Example
// Declare a variable
int myNum;
// Assign a value to the variable
myNum = 15;
Output Variables
You learned from the output chapter that you can output values/print text with the printf()
function:
Example
printf("Hello World!");
In many other programming languages (like Python, Java, and C++), you would normally use a
print function to display the value of a variable. However, this is not possible in C:
Example
int myNum = 15;
printf(myNum); // Nothing happens

To output variables in C, you must get familiar with something called "format specifiers".
Format Specifiers
Format specifiers are used together with the printf() function to tell the compiler what type of
data the variable is storing. It is basically a placeholder for the variable value.
A format specifier starts with a percentage sign %, followed by a character.
For example, to output the value of an int variable, you must use the format specifier %d or %i
surrounded by double quotes, inside the printf() function:

Example
int myNum = 15;
printf("%d", myNum); // Outputs 15

To print other types, use %c for char and %f for float:


Example
// Create variables
int myNum = 15; // Integer (whole number)
float myFloatNum = 5.99; // Floating point number
char myLetter = 'D'; // Character
// Print variables
printf("%d\n", myNum);
printf("%f\n", myFloatNum);
printf("%c\n", myLetter);

To combine both text and a variable, separate them with a comma inside the printf() function:
Example
int myNum = 15;
printf("My favorite number is: %d", myNum);
To print different types in a single printf() function, you can use the following:

Example
int myNum = 15;
char myLetter = 'D';
printf("My number is %d and my letter is %c", myNum, myLetter);

Change Variable Values


Note: If you assign a new value to an existing variable, it will overwrite the previous value:
Example
int myNum = 15; // myNum is 15
myNum = 10; // Now myNum is 10

You can also assign the value of one variable to another:


Example
int myNum = 15;
int myOtherNum = 23;
// Assign the value of myOtherNum (23) to myNum
myNum = myOtherNum;
// myNum is now 23, instead of 15
printf("%d", myNum);

Or copy values to empty variables:

Example
// Create a variable and assign the value 15 to it
int myNum = 15;

// Declare a variable without assigning it a value


int myOtherNum;

// Assign the value of myNum to myOtherNum


myOtherNum = myNum;

// myOtherNum now has 15 as a value


printf("%d", myOtherNum);
Add Variables Together
To add a variable to another variable, you can use the + operator:

Example
int x = 5;
int y = 6;
int sum = x + y;
printf("%d", sum);
Declare Multiple Variables
To declare more than one variable of the same type, use a comma-separated list:
Example
int x = 5, y = 6, z = 50;
printf("%d", x + y + z);
You can also assign the same value to multiple variables of the same type:

Example
int x, y, z;
x = y = z = 50;
printf("%d", x + y + z);
C Variable Names
All C variables must be identified with unique names.

These unique names are called identifiers.

Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume).

Note: It is recommended to use descriptive names in order to create understandable and


maintainable code:

Example
// Good
int minutesPerHour = 60;

// OK, but not so easy to understand what m actually is


int m = 60;
The general rules for naming variables are:

Names can contain letters, digits and underscores


Names must begin with a letter or an underscore (_)
Names are case sensitive (myVar and myvar are different variables)
Names cannot contain whitespaces or special characters like !, #, %, etc.
Reserved words (such as int) cannot be used as names
Real-Life Example
Often in our examples, we simplify variable names to match their data type (myInt or myNum
for int types, myChar for char types etc). This is done to avoid confusion.

However, if you want a real-life example on how variables can be used, take a look at the
following, where we have made a program that stores different data of a college student:

Example
// Student data
int studentID = 15;
int studentAge = 23;
float studentFee = 75.25;
char studentGrade = 'B';

// Print variables
printf("Student id: %d\n", studentID);
printf("Student age: %d\n", studentAge);
printf("Student fee: %f\n", studentFee);
printf("Student grade: %c", studentGrade);
Data Types
As explained in the Variables chapter, a variable in C must be a specified data type, and you must
use a format specifier inside the printf() function to display it:

Example
// Create variables
int myNum = 5; // Integer (whole number)
float myFloatNum = 5.99; // Floating point number
char myLetter = 'D'; // Character

// Print variables
printf("%d\n", myNum);
printf("%f\n", myFloatNum);
printf("%c\n", myLetter);

Basic Data Types


The data type specifies the size and type of information the variable will store.

In this tutorial, we will focus on the most basic ones:

Data Size Description


Type

int 2 or 4 Stores whole numbers, without decimals


bytes

float 4 bytes Stores fractional numbers, containing one or more decimals.


Sufficient for storing 6-7 decimal digits

double 8 bytes Stores fractional numbers, containing one or more decimals.


Sufficient for storing 15 decimal digits

char 1 byte Stores a single character/letter/number, or ASCII values

Basic Format Specifiers


There are different format specifiers for each data type. Here are some of them:

Format Data Type


Specifier

%d or %i Int

%f Float

%lf Double

%c Char

%s Used for strings (text), which you will learn more about in a later
chapter
Set Decimal Precision
You have probably already noticed that if you print a floating point number, the output will show
many digits after the decimal point:

Example
float myFloatNum = 3.5;
double myDoubleNum = 19.99;

printf("%f\n", myFloatNum); // Outputs 3.500000


printf("%lf", myDoubleNum); // Outputs 19.990000

If you want to remove the extra zeros (set decimal precision), you can use a dot ( .) followed by a
number that specifies how many digits that should be shown after the decimal point:

Example
float myFloatNum = 3.5;

printf("%f\n", myFloatNum); // Default will show 6 digits after the decimal point
printf("%.1f\n", myFloatNum); // Only show 1 digit
printf("%.2f\n", myFloatNum); // Only show 2 digits
printf("%.4f", myFloatNum); // Only show 4 digits

Range of int long and long long:


The range of integer data types, such as `int`, `long`, and `long long`, can vary depending on the
architecture and compiler used. However, I can provide you with common ranges for these data
types on many modern systems, which follow the C99 standard:

1. **int**:
- Typically 32 bits on most systems.
- Range: -2,147,483,648 to 2,147,483,647 (for a signed int).
- Range: 0 to 4,294,967,295 (for an unsigned int).

2. **long**:
- Often 32 bits on 32-bit systems.
- Often 64 bits on 64-bit systems.
- Range: -2,147,483,648 to 2,147,483,647 (for a signed long on a 32-bit system).
- Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (for a signed long on a 64-
bit system).
- Range: 0 to 4,294,967,295 (for an unsigned long on a 32-bit system).
- Range: 0 to 18,446,744,073,709,551,615 (for an unsigned long on a 64-bit system).

3. **long long**:
- Typically 64 bits on most systems.
- Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (for a signed long long).
- Range: 0 to 18,446,744,073,709,551,615 (for an unsigned long long).

Keep in mind that these ranges are common but not guaranteed. To determine the exact range for
these data types on your specific system, you can use the `limits.h` header and its constants like
`INT_MIN`, `INT_MAX`, `LONG_MIN`, `LONG_MAX`, `LLONG_MIN`, and
`LLONG_MAX`. These constants are defined in the C standard library and provide information
about the minimum and maximum representable values for each data type.

Type of Variables, Local, Global and Static


Here is the difference between local, global, and static variables in C:
 Local variables: are created inside a function and can only be accessed from within that
function.
 Global variables: can be accessed from anywhere in the program.
 Static variables: are like global variables, but they can only be accessed from within the
file in which they are declared.
Example of a local variable:
void my_function()
{
int local_variable;
// ...
}
In this example, local_variable is a local variable because it is declared inside
the my_function() function. It can only be accessed from within that function.
Example of a global variable
int global_variable;
void my_function()
{
// ...
global_variable = 10;
}
In this example, global_variable is a global variable because it is not declared inside any
function. It can be accessed from anywhere in the program.
Example of a static variable
static int static_variable;
void my_function() {
// ...
static_variable = 10;
}
In this example, static_variable is a static variable because it is declared with
the static keyword. It can only be accessed from within the my_function() function.
Advantages of each variable type
Local variables are good for storing data that is only needed within a single function. This can
help to keep the code organized and easy to read.
Global variables are good for storing data that needs to be accessed from multiple
functions. However, it is important to use caution when using global variables, as they can easily
be modified from anywhere in the program.
Static variables are a good compromise between local variables and global variables. They can
be accessed from multiple functions, but they are only visible within the file in which they are
declared. This can help to keep the code organized and easy to read, while still allowing data to
be accessed from multiple functions.
Type Conversion
Sometimes, you have to convert the value of one data type to another type. This is known as type
conversion.

For example, if you try to divide two integers, 5 by 2, you would expect the result to be 2.5. But
since we are working with integers (and not floating-point values), the following example will just
output 2:

Example
int x = 5;
int y = 2;
int sum = 5 / 2;

printf("%d", sum); // Outputs 2

To get the right result, you need to know how type conversion works.

There are two types of conversion in C:

 Implicit Conversion (automatically)


 Explicit Conversion (manually)

Implicit Conversion
Implicit conversion is done automatically by the compiler when you assign a value of one type to
another.

For example, if you assign an int value to a float type:

Example
// Automatic conversion: int to float
float myFloat = 9;

printf("%f", myFloat); // 9.000000

As you can see, the compiler automatically converts the int value 9 to a float value of 9.000000.

This can be risky, as you might lose control over specific values in certain situations.
Especially if it was the other way around - the following example automatically converts the float
value 9.99 to an int value of 9:

Example
// Automatic conversion: float to int
int myInt = 9.99;

printf("%d", myInt); // 9

What happened to .99? We might want that data in our program! So be careful. It is important that
you know how the compiler work in these situations, to avoid unexpected results.

As another example, if you divide two integers: 5 by 2, you know that the sum is 2.5. And as you
know from the beginning of this page, if you store the sum as an integer, the result will only display
the number 2. Therefore, it would be better to store the sum as a float or a double, right?

Example
float sum = 5 / 2;

printf("%f", sum); // 2.000000

Why is the result 2.00000 and not 2.5? Well, it is because 5 and 2 are still integers in the division. In
this case, you need to manually convert the integer values to floating-point values. (see below).

Explicit Conversion
Explicit conversion is done manually by placing the type in parentheses () in front of the value.

Considering our problem from the example above, we can now get the right result:

Example
// Manual conversion: int to float
float sum = (float) 5 / 2;

printf("%f", sum); // 2.500000

You can also place the type in front of a variable:


Example
int num1 = 5;
int num2 = 2;
float sum = (float) num1 / num2;

printf("%f", sum); // 2.500000

And since you learned about "decimal precision" in the previous chapter, you could make the output
even cleaner by removing the extra zeros (if you like):

Example
int num1 = 5;
int num2 = 2;
float sum = (float) num1 / num2;

printf("%.1f", sum); // 2.5

Constants
If you don't want others (or yourself) to change existing variable values, you can use
the const keyword.

This will declare the variable as "constant", which means unchangeable and read-only:

Example
const int myNum = 15; // myNum will always be 15
myNum = 10; // error: assignment of read-only variable 'myNum'

You should always declare the variable as constant when you have values that are unlikely to change:

Example
const int minutesPerHour = 60;
const float PI = 3.14;
Notes On Constants
When you declare a constant variable, it must be assigned with a value:

Example
Like this:

const int minutesPerHour = 60;

This however, will not work:

const int minutesPerHour;


minutesPerHour = 60; // error

Good Practice
Another thing about constant variables, is that it is considered good practice to declare them with
uppercase. It is not required, but useful for code readability and common for C programmers:

Example
const int BIRTHYEAR = 1980;
Storage classes: Automatic, Register, Static and
extern:
C Storage Classes are used to describe the features of a variable/function. These features
basically include the scope, visibility, and lifetime which help us to trace the existence of a
particular variable during the runtime of a program.
C language uses 4 storage classes, namely:

1. auto
This is the default storage class for all the variables declared inside a function or a block.
Hence, the keyword auto is rarely used while writing programs in C language. Auto variables
can be only accessed within the block/function they have been declared and not outside them
(which defines their scope). Of course, these can be accessed within nested blocks within the
parent block/function in which the auto variable was declared.
However, they can be accessed outside their scope as well using the concept of pointers given
here by pointing to the very exact memory location where the variables reside. They are
assigned a garbage value by default whenever they are declared.
2. extern
Extern storage class simply tells us that the variable is defined elsewhere and not within the
same block where it is used. Basically, the value is assigned to it in a different block and this
can be overwritten/changed in a different block as well. So an extern variable is nothing but a
global variable initialized with a legal value where it is declared in order to be used elsewhere.
It can be accessed within any function/block.
Also, a normal global variable can be made extern as well by placing the ‘extern’ keyword
before its declaration/definition in any function/block. This basically signifies that we are not
initializing a new variable but instead, we are using/accessing the global variable only. The
main purpose of using extern variables is that they can be accessed between two different files
which are part of a large program.
3. static
This storage class is used to declare static variables which are popularly used while writing
programs in C language. Static variables have the property of preserving their value even after
they are out of their scope! Hence, static variables preserve the value of their last use in their
scope. So we can say that they are initialized only once and exist till the termination of the
program. Thus, no new memory is allocated because they are not re-declared.
Their scope is local to the function to which they were defined. Global static variables can be
accessed anywhere in the program. By default, they are assigned the value 0 by the compiler.
4. register
This storage class declares register variables that have the same functionality as that of the auto
variables. The only difference is that the compiler tries to store these variables in the register of
the microprocessor if a free register is available. This makes the use of register variables to be
much faster than that of the variables stored in the memory during the runtime of the program.
If a free registration is not available, these are then stored in the memory only. Usually, a few
variables which are to be accessed very frequently in a program are declared with the register
keyword which improves the running time of the program. An important and interesting point
to be noted here is that we cannot obtain the address of a register variable using pointers.

Syntax

To specify the storage class for a variable, the following syntax is to be followed:
storage_class var_data_type var_name;

Example

Functions follow the same syntax as given above for variables. Have a look at the following C
example for further clarification:
// A C program to demonstrate different storage
// classes
#include <stdio.h>

// declaring the variable which is to be made extern


// an initial value can also be initialized to x
int x;
void autoStorageClass()
{

printf("\nDemonstrating auto class\n\n");

// declaring an auto variable (simply


// writing "int a=32;" works as well)
auto int a = 32;

// printing the auto variable 'a'


printf("Value of the variable 'a'"
" declared as auto: %d\n",
a);

printf("--------------------------------");
}

void registerStorageClass()
{

printf("\nDemonstrating register class\n\n");

// declaring a register variable


register char b = 'G';

// printing the register variable 'b'


printf("Value of the variable 'b'"
" declared as register: %d\n",
b);
printf("--------------------------------");
}

void externStorageClass()
{

printf("\nDemonstrating extern class\n\n");

// telling the compiler that the variable


// x is an extern variable and has been
// defined elsewhere (above the main
// function)
extern int x;

// printing the extern variables 'x'


printf("Value of the variable 'x'"
" declared as extern: %d\n",
x);

// value of extern variable x modified


x = 2;

// printing the modified values of


// extern variables 'x'
printf("Modified value of the variable 'x'"
" declared as extern: %d\n",
x);

printf("--------------------------------");
}

void staticStorageClass()
{
int i = 0;

printf("\nDemonstrating static class\n\n");

// using a static variable 'y'


printf("Declaring 'y' as static inside the loop.\n"
"But this declaration will occur only"
" once as 'y' is static.\n"
"If not, then every time the value of 'y' "
"will be the declared value 5"
" as in the case of variable 'p'\n");

printf("\nLoop started:\n");

for (i = 1; i < 5; i++) {

// Declaring the static variable 'y'


static int y = 5;

// Declare a non-static variable 'p'


int p = 10;

// Incrementing the value of y and p by 1


y++;
p++;
// printing value of y at each iteration
printf("\nThe value of 'y', "
"declared as static, in %d "
"iteration is %d\n",
i, y);

// printing value of p at each iteration


printf("The value of non-static variable 'p', "
"in %d iteration is %d\n",
i, p);
}
printf("\nLoop ended:\n");
printf("--------------------------------");
}
int main()
{
printf("A program to demonstrate"
" Storage Classes in C\n\n");
// To demonstrate auto Storage Class
autoStorageClass();
// To demonstrate register Storage Class
registerStorageClass();
// To demonstrate extern Storage Class
externStorageClass();
// To demonstrate static Storage Class
staticStorageClass();
// exiting
printf("\n\nStorage Classes demonstrated");
return 0;
}

You might also like