IP Unit-1-1
IP Unit-1-1
Tech, I-Semester
UNIT-1
Q1)Explain the History of Computers?
The first counting device was used by the primitive people. They used sticks, stones and bones
as counting tools. As human mind and technology improved with time more computing devices
were developed. Some of the popular computing devices starting with the first to recent ones
are described below:
Abacus: The history of computer begins with the birth of abacus which is
believed to be the first computer. It is said that Chinese invented Abacus
around 4,000 years ago.
It was a wooden rack which has metal rods with beads mounted on them.
The beads were moved by the abacus operator according to some rules to
perform arithmetic calculations. Abacus is still used in some countries like
China, Russia and Japan. An image of this tool is shown beside:
Napier's Bones: It was a manually-operated calculating device which was
invented by John Napier (1550-1617) of Merchiston. In this calculating tool, he
used 9 different ivory strips or bones marked with numbers to multiply and
divide. So, the tool became known as "Napier's Bones. It was also the first
machine to use the decimal point.
Pascaline: Pascaline is also known as Arithmetic Machine or Adding
Machine. It was invented between 1642 and 1644 by a French mathematician-
philosopher Biaise Pascal. It is believed that it was the first mechanical and
automatic calculator. Pascal invented this machine to help his father, a tax
accountant. It could only perform addition and subtraction. It was a wooden
box with a series of gears and wheels. When a wheel is rotated one
revolution, it rotates the neighboring wheel. A series of windows is given on the top of the
wheels to read the totals. An image of this tool is shown beside:
Stepped Reckoner or Leibnitz wheel: It was developed by a German
mathematician-philosopher Gottfried Wilhelm Leibnitz in 1673. He improved
Pascal's invention to develop this machine. It was a digital mechanical calculator
which was called the stepped reckoner as instead of gears it was made of fluted
drums. See the following image:
Difference Engine: In the early 1820s, it was designed by Charles Babbage
who is known as "Father of Modern Computer". It was a mechanical computer
which could perform simple calculations. It was a steam driven calculating
machine designed to solve tables of numbers like logarithm tables.
1)Input Unit: All the data received by the computer goes through the input unit. The input
unit comprises different devices. Like a mouse, keyboard, scanner, etc. In other words, each of
these devices acts as a mediator between the users and the computer.
The data that is to be processed is put through the input unit. The computer accepts the raw
data in binary form. It then processes the data, and produces the desired output.
The 3 major functions of the input unit are-
Q5)What are the Applications of Computers? (or) What are the uses of
Computers?
Computers play a role in every field of life. They are used in homes, business, educational
institutions, research organizations, medical field, government offices, entertainment, etc.
1.Home: Computers are used at homes for several purposes like online bill payment,
watching movies or shows at home, home tutoring, social media access, playing games, internet
access, etc. They provide communication through electronic mail. They help to avail work from
home facility for corporate employees. Computers help the student community to avail online
educational support.
2.Medical Field: Computers are used in hospitals to maintain a database of patients’
history, diagnosis, X-rays, live monitoring of patients, etc. Surgeons nowadays use robotic
surgical devices to perform delicate operations, and conduct surgeries remotely. Virtual reality
technologies are also used for training purposes. It also helps to monitor the fetus inside the
mother’s womb.
3.Entertainment: Computers help to watch movies online, play games online; act as a
virtual entertainer in playing games, listening to music, etc. MIDI instruments greatly help
people in the entertainment industry in recording music with artificial instruments. Videos can
be fed from computers to full screen televisions. Photo editors are available with fabulous
features.
4.Industry: Computers are used to perform several tasks in industries like managing
inventory, designing purpose, creating virtual sample products, interior designing, video
conferencing, etc. Online marketing has seen a great revolution in its ability to sell various
products to inaccessible corners like interior or rural areas. Stock markets have seen phenomenal
participation from different levels of people through the use of computers.
5.Education: Computers are used in education sector through online classes, online
examinations, referring e-books, online tutoring, etc. They help in increased use of audio-visual
aids in the education field.
6.Government: In government sectors, computers are used in data processing, maintaining
a database of citizens and supporting a paperless environment. The country’s defense
organizations have greatly benefitted from computers in their use for missile development,
satellites, rocket launches, etc.
7.Banking: In the banking sector, computers are used to store details of customers and
conduct transactions, such as withdrawal and deposit of money through ATMs. Banks have
reduced manual errors and expenses to a great extent through extensive use of computers.
8.Business: Nowadays, computers are totally integrated into business. The main objective of
business is transaction processing, which involves transactions with suppliers, employees or
customers. Computers can make these transactions easy and accurate. People can analyze
investments, sales, expenses, markets and other aspects of business using computers.
9.Training: Many organizations use computer-based training to train their employees, to
save money and improve performance. Video conferencing through computers allows saving of
time and travelling costs by being able to connect people in various locations.
10.Arts: Computers are extensively used in dance, photography, arts and culture. The fluid
movement of dance can be shown live via animation. Photos can be digitized using computers.
11.Bar Code Readers: Bar Code Reader is a device used for reading
bar coded data (data in form of light and dark lines). Bar coded data is
generally used in labelling goods, numbering the books etc. It may be a
hand held scanner or may be embedded in a stationary scanner. Bar Code
Reader scans a bar code image, converts it into an alphanumeric value
which is then fed to the computer to which bar code reader is connected.
Daisy Wheel: Head is lying on a wheel and pins corresponding to characters are like petals of
Daisy (flower name) that is why it is called Daisy Wheel Printer. These printers are generally
used for word-processing in offices which require a few letters to be sent here and there with
very nice quality.
Advantages:
More reliable than DMP
Better quality
The fonts of character can be easily changed
Disadvantages:
Slower than DMP
Noisy
More expensive than DMP
b)Line Printers: Line printers are the printers which print one line at a time.
These are of further two types
i)Drum Printer
ii)Chain Printer
i)Drum Printer: This printer is like a drum in shape so it is called drum
printer. The surface of drum is divided into number of tracks. Total tracks are equal to size of
paper i.e. for a paper width of 132 characters, drum will have 132 tracks. A character set is
embossed on track. The different character sets available in the market are 48 character set, 64
and 96 characters set. One rotation of drum prints one line. Drum printers are fast in speed and
can print 300 to 2000 lines per minute.
Advantages:
Very high speed
Disadvantages:
Very expensive
Characters fonts cannot be changed
ii)Chain Printer: In this printer, chain of character sets are used so it is called Chain Printer. A
standard character set may have 48, 64, or 96 characters.
Advantages:
Character fonts can easily be changed.
Different languages can be used with the same printer.
Disadvantages:
Noisy
ii)Non-impact Printers: Non-impact printers print the characters without using ribbon.
These printers print a complete page at a time so they are also called as Page Printers.
P.Madhubabu M.C.A & M.Tech 10
Introduction to Programming I-B.Tech, I-Semester
These printers are of two types
a) Laser Printers
b) Inkjet Printers
a)Laser Printers: These are non-impact page printers. They use laser lights to produce the dots
needed to form the characters to be printed on a page.
Advantages:
Very high speed
Very high quality output
Give good graphics quality
Support many fonts and different character size
Disadvantages:
Expensive.
Cannot be used to produce multiple copies of a document in a single printing.
b)Inkjet Printers: Inkjet printers are non-impact character printers based on a relatively new
technology. They print characters by spraying small drops of ink onto paper. Inkjet printers
produce high quality output with presentable features.
They make less noise because no hammering is done and these have many styles of printing
modes available. Colour printing is also possible. Some models of Inkjet printers can produce
multiple copies of printing also.
Advantages:
High quality printing
More reliable
Disadvantages:
Expensive as cost per page is high
Slow as compared to laser printer
Q8)What are the classification of Computers? (or) What are the types
of Computers?
1.Primary or Main Memory: Primary memory is also known as the computer system's main
memory that communicates directly within the CPU, Auxiliary memory and the Cache memory.
Main memory is used to kept programs or data when the processor is active to use them. When
a program or data is activated to execute, the processor first loads instructions or programs
from secondary memory into main memory, and then the processor starts execution. Accessing
or executing of data from primary memory is faster because it has a cache or register memory
that provides faster response, and it is located closer to the CPU. The primary memory is
volatile, which means the data in memory can be lost if it is not saved when a power failure
occurs. It is costlier than secondary memory, and the main memory capacity is limited as
compared to secondary memory.
The primary memory is further divided into two parts:
a) RAM (Random Access Memory)
b) ROM (Read Only Memory)
a)Random Access Memory (RAM): Random Access Memory (RAM) is one of the faster
types of main memory accessed directly by the CPU. It is the hardware in a computer device to
temporarily store data, programs or program results. It is used to
read/write data in memory until the machine is working. It is volatile,
which means if a power failure occurs or the computer is turned off,
the information stored in RAM will be lost. All data stored in
computer memory can be read or accessed randomly at any time.
There are two types of RAM:
SRAM
DRAM
DRAM: DRAM (Dynamic Random-Access Memory) is a type of RAM that is used for the
dynamic storage of data in RAM. In DRAM, each cell carries one-bit information. The cell is
made up of two parts: a capacitor and a transistor. The size of the capacitor and the transistor is
so small, requiring millions of them to store on a single chip. Hence, a DRAM chip can hold
more data than an SRAM chip of the same size. However, the capacitor needs to be
continuously refreshed to retain information because DRAM is volatile. If the power is switched
off, the data store in memory is lost.
SRAM: SRMA (Static Random-Access Memory) is a type of RAM used to store static data in the
memory. It means to store data in SRAM remains active as long as the computer system has a
power supply. However, data is lost in SRAM when power failures have occurred.
Read-Only Memory (ROM)
P.Madhubabu M.C.A & M.Tech 13
Introduction to Programming I-B.Tech, I-Semester
b)ROM: ROM is a memory device or storage medium that is used to permanently store
information inside a chip. It is a read-only memory that can only read stored information, data
or programs, but we cannot write or modify anything. A ROM contains some important
instructions or program data that are required to start or boot a computer. It is a non-
volatile memory; it means that the stored information cannot be
lost even when the power is turned off or the system is shut down.
Types of ROM: There are five types of Read Only Memory:
a) MROM (Masked Read Only Memory)
b) PROM (Programmable Read Only Memory)
c) EPROM (Erasable and Programmable Read Only Memory)
d) EEPROM (Electrically Erasable and Programmable Read Only
Memory)
e) Flash ROM
a)MROM (Masked Read Only Memory): MROM is the oldest type of read-only memory
whose program or data is pre-configured by the integrated circuit manufacture at the time of
manufacturing. Therefore, a program or instruction stored within the MROM chip cannot be
changed by the user.
b)PROM (Programmable Read Only Memory): It is a type of digital read-only memory, in
which the user can write any type of information or program only once. It means it is the
empty PROM chip in which the user can write the desired content or program only once using
the special PROM programmer or PROM burner device; after that, the data or instruction
cannot be changed or erased.
c)EPROM (Erasable and Programmable Read Only Memory): It is the type of read only
memory in which stored data can be erased and re-programmed only once in the EPROM
memory. It is a non-volatile memory chip that holds data when there is no power supply and
can also store data for a minimum of 10 to 20 years. In EPROM, if we want to erase any stored
data and re-programmed it, first, we need to pass the ultraviolet light for 40 minutes to erase
the data; after that, the data is re-created in EPROM.
d)EEPROM (Electrically Erasable and Programmable Read Only Memory): The EEROM is
an electrically erasable and programmable read only memory used to erase stored data using a
high voltage electrical charge and re-programmed it. It is also a non-volatile memory whose
data cannot be erased or lost; even the power is turned off. In EEPROM, the stored data can be
erased and reprogrammed up to 10 thousand times, and the data erase one byte at a time.
e)Flash ROM: Flash memory is a non-volatile storage memory chip that can be written or
programmed in small units called Block or Sector. Flash Memory is an EEPROM form of
computer memory, and the contents or data cannot be lost when the power source is turned
off. It is also used to transfer data between the computer and digital devices.
2.Secondary Memory: Secondary memory is a permanent storage space to hold a large
amount of data. Secondary memory is also known as external memory that representing the
various storage media (hard drives, USB, CDs, flash drives and DVDs) on which the computer
data and program can be saved on a long term basis.
Types of Secondary Memory:
The following are the types of secondary memory devices:
Hard Disk
i)Hard Disk: A hard disk is a computer's permanent storage device. It is a
non-volatile disk that permanently stores data, programs, and files, and
cannot lose store data when the computer's power source is switched off.
Typically, it is located internally on computer's motherboard that stores and
retrieves data using one or more rigid fast rotating disk platters inside an air-
sealed casing. It is a large storage device, found on every computer or laptop
for permanently storing installed software, music, text documentation, videos, operating system,
and data until the user did not delete.
2.Input/output Symbol: The input symbol is used to represent the input data, and the
output symbol is used to display the output operation. The symbol given below is used for
representing the Input/output symbol.
3.Processing Symbol: It is represented in a flowchart with the help of a rectangle box used
to represent the arithmetic and data movement instructions. The symbol given below is used to
represent the processing symbol.
4.Decision Symbol: Diamond symbol is used for represents decision-making statements. The
symbol given below is used to represent the decision symbol.
5.Connector Symbol: The connector symbol is used if flows discontinued at some point and
continued again at another place. The following symbol is the representation of the connector
symbol.
6.Flow lines: It represents the exact sequence in which instructions are executed. Arrows are
used to represent the flow lines in a flowchart. The symbol given below is used for representing
the flow lines:
Advantages of Flowchart in C:
Following are the various advantages of flowchart:
1. Communication: A flowchart is a better way of communicating the logic of a
program.
2. Synthesis: Flowchart is used as working models in designing new programs and
software systems.
3. Efficient Coding: Flowcharts act as a guide for a programmer in writing the actual
code in a high-level language.
4. Proper Debugging: Flowcharts help in the debugging process.
5. Effective Analysis: Effective analysis of logical programs can be easily done with the
help of a related flowchart.
6. Proper Documentation: Flowchart provides better and proper documentation. It
consists of various activities such as collecting, organizing, storing, and maintaining all
related program records.
7. Testing: A flowchart helps in the testing process.
8. Efficient program maintenance: The maintenance of the program becomes easy
with the help of a flowchart.
Disadvantages of Flowchart in C:
Following are the various disadvantages of flowchart:
1. Time-consuming: Designing a flowchart is a very time-consuming process.
2. Complex: It isn't easy to draw a flowchart for large and complex programs.
3. There is no standard in the flowchart: there is no standard to determine the
quantity of detail.
4. Difficult to modify: It is very difficult to modify the existing flowchart.
Example: To prepare a flowchart to determine the greatest of two numbers. Here we use the
decision symbol. We also combine the two reads for numbers A and B in one box.
The steps are :
1. Start
2. Get two number A and B.
3. If A > B then print A else print B.
4. Stop
The file which contains c program instructions in high level language is said to be source
code. Every c program source file is saved with .c extension, for example Sample.c.
Whenever we press Alt + F9 the source file is submitted to the compiler. Compiler checks
for the errors, if there are any errors, it returns list of errors, otherwise generates object code in
a file with name Sample.obj and submit it to the linker. Linker combines the code from specified
header file into object file and generates executable file as Sample.exe. With this compilation
process completes.
Now, we need to Run the executable file (Sample.exe). To run a program we press Ctrl
+ F9. When we press Ctrl + F9 the executable file is submitted to the CPU. Then CPU performs
the task according to the instructions written in that program and place the result into
UserScreen.
Then we press Alt + F5 to open UserScreen and check the result of the program.
These primary data types are divided into 3 categories . They are:
a)Integral Datatypes
b)Floating point Datatypes
c)Character Datatypes
a)Integral Datatypes: Integral data types are used to allocate memory for integer values.
int, short int, long int are signed datatypes used to store positive values and also negative
values.
unsigned int, unsigned short int, unsigned long int types allows only positive values.
These integer datatype can also accepts octal values, hexa decimal values.
signed int – 2bytes -> -32,768 to +32767
unsigned int – 2bytes -> 0 to 65535
Syntax: Datatype variable-name; (or) Datatype identifier;
Ex: int a=26; //decimal representation
int a=032; //octal representation
int a=0x1a; //hexa decimal representation
b)Floating point Datatypes: float, double, long double are the floating datatypes, which are
used to store decimal values. float takes 4 bytes of memory and double takes 8 bytes of
memory it is capable of representing about twice as much precision as a float. The long double
takes 10 bytes of memory.
Ex: float a;
a = 0.143;
float pi;
double pi_sqr;
pi = 3.1417;
pi_sqr = pi * pi;
c)Character Data Types: signed char, unsigned char are the character datatypes.
Signed char – 1 byte -128 to +127
Unsigned char – 1 byte 0 to 255
signed char is used to store alphabets and unsigned char is used to store unsigned integer value
upto 255.
It allocates 1 byte memory for single character and also allocate memory for 1 byte to
unsigned integer. In ‘c’ language every character has a decimal value called ASCII(American
Standard Code Information Interchange)
Ex: char ch1 = ‘a’;
printf(“%c”,ch1);
printf(“%d”,ch2);
2.UserDefined Datatypes: structures, unions, typedef are examples to Userdefined datatypes.
The c language provides to create your own names for data types with this typedef keyword.
Ex: typedef int integer;
integer a, b;
Makes the name integer a synonym for int. it is used same as int.
The typedef declaration does not create a new type in any sense. It adds a new name for the
existing type. It makes easy to identify which purpose the variable is used.
1.Keywords: The C keywords are reserved words by the compiler. All the C keywords have
been assigned fixed meaning. The keywords cannot be used as variable names because they
have been assigned fixed jobs. The C language has 32 keywords.
2.Identifiers: Identifier can be defined as the name of the variable, which holds a value and
stores that value in the memory.
Example: char ch=’x’;
int a=10;
float b=5.7;
double c=234234.5656;
in the above example, variable names: ch, a, b, c are called as Identifiers.
3.Constants: A constant is a fixed value that cannot be altered during the execution of a
program. There are several types of constants in C.
3.2)Character Constants:
a)Single character constants: A character constant is a single constant is a single character.
They are also represented with a single digit or a single symbol or white space enclosed within
a pair of single quote marks.
Ex: ‘a’, ‘A’, ‘8’ etc.
b) String constants: String constants are sequence of character enclosed within a double
quote marks.
Ex: “career”, “welcome” etc.
4.Strings: A String is an array of characters ended with a null character(\0). This null
character indicates that string has ended. Strings are always enclosed with double quotes(“ “).
Let us see how to declare String in C language:
Examples:
char string[20] = {‘s’,’t’,’u’,’d’,’y’, ‘\0’};
char string[20] = “demo”;
char string[] = “demo”;
5.Special Symbols: The following special symbols are used in C having some special
meaning and thus, cannot be used for some other purpose.
Some special characters are used in C, and they have a special meaning which cannot be used
for another purpose.
i) Square brackets[]: The opening and closing brackets represent the single and
multidimensional subscripts.
ii) Simple brackets ( ) : It is used in function declaration and function calling. For example,
printf() is a pre-defined function.
iii) Curly braces { } : It is used in the opening and closing of the code. It is used in the
opening and closing of the loops.
iv) Comma (,): It is used for separating for more than one statement and for example,
separating function parameters in a function call, separating the variable when printing
the value of more than one variable using a single printf statement.
v) Hash/pre-processor (#): It is used for pre-processor directive. It basically denotes that
we are using the header file.
vi) Asterisk (*): This symbol is used to represent pointers and also used as an operator for
multiplication.
vii) Tilde (~): It is used as a destructor to free memory.
viii) Period (.): It is used to access a member of a structure or a union.
6.Operators: C operators are symbols that triggers an action when applied to C variables
and other objects. The data items on which operators act upon are called operands.
Depending on the number of operands that an operator can act upon, operators can be
classified as follows:
i)Unary Operators: A unary operator is an operator applied to the single operand.
Example:
increment operator (++),
decrement operator (--),
sizeof,
(type)*.
ii)Binary Operators: The binary operator is an operator applied between two operands. The
following is the list of the binary operators:
a) Arithemetic Operators
b) Relational Operators
c) Logical Operators
1)Documentation Section
2)Link Section
3)Definition Section
4)Global Declaration section
5)Function main()
5.1)Declaration Part
5.2)Executable Part
6)Sub-Program Section
Output:
x = 107, z = 108.000000
Syntax/Declaration:
destination_datatype = (target_datatype)variable;
target_datatype indicated the data type to which the final result is converted.
Output:
sum = 2
In type casting, a data type is converted Whereas in type conversion, a data type is
1. into another data type by a programmer converted into another data type by a
using casting operator. compiler.
Type casting takes place during the Whereas type conversion is done at the
5.
program design by programmer. compile time.
Type casting is also called narrowing Whereas type conversion is also called
conversion because in this, the widening conversion because in this, the
6.
destination data type may be smaller destination data type can not be smaller
than the source data type. than the source data type.
Type casting is more efficient and Whereas type conversion is less efficient
8.
reliable. and less reliable.