Sie sind auf Seite 1von 122

COMPUTER

PROGRAMMING
(18CPL17)

VIDYAVARDHAKA COLLEGE OF ENGINEERING


MYSURU-570002

Department
of

1
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Computer Science &


Engineering

FIRST SEMESTER
LABORATORY MANUAL

2
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

"COMPUTER PROGRAMMING
LABORATORY"
(18CPL17)

3
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

VISION OF THE INSTITUTION

Vidyavardhaka College of
Engineering shall be a
leading Institution in
engineering and management
education enabling
individuals for significant
contribution to the society
4
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

MISSION OF THE INSTITUTION


 To provide the best teaching - learning environment
through competent staff and excellent infrastructure
 To inculcate professional ethics, leadership qualities,
communication and entrepreneurial skills to meet the
societal needs
 To promote innovation through research and development
 To strengthen industry-institute interaction for knowledge
sharing

VISION OF THE DEPARTMENT

The Department of Computer


Science and Engineering shall
create professionally
5
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

competent and socially


responsible engineers
capable of working in global
environment.
MISSION OF THE DEPARTMENT
 Promote best practices in teaching-learning, with
dedicated staff and supportive infrastructure to create
technically competent engineers
 Inculcate ethical and cultural values, communication and
Entrepreneurial skills
 Provide exposure of tools and technologies necessary to
pursue higher education and research
 Improve Industry-Institute relationship for mutual benefit

6
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Computer Programming Laboratory


VTU SYLLABUS
Subject Code: 18CPL17 I.A. Marks : 40
Hours/Week : 02 Exam Hours: 03
Total Hours : 30 Exam Marks: 60

1. Familiarization with computer hardware and programming environment, concept of naming


the program files, storing, compilation, execution and debugging, taking any simple C- code.

PART A

7
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

2. Develop a program to solve simple computational problems using arithmetic


expressions and use of each operator leading to simulation of a commercial
calculator. (No built-in math function)
3. Develop a program to compute the roots of a quadratic equation by accepting the
coefficients. Print appropriate messages.
4. Develop a program to find the reverse of a positive integer and check for palindrome
or not. Display appropriate messages.
5. An electricity board charges the following rates for the use of electricity: for the first
200 units 80 paise per unit: for the next 100 units 90 paise per unit: beyond 300 units
Rs 1 per unit. All users are charged a minimum of Rs. 100 as meter charge. If the
total amount is more than Rs 400, then an additional surcharge of 15% of total
amount is charged. Write a program to read the name of the user, number of units
consumed and print out the charges.

8
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

6. Introduce 1D Array manipulation and implement Binary search. Implement using


functions to check whether the given number is prime and display appropriate
messages. (No built-in math function)

7. Implement using functions to check whether the given number is prime and display
appropriate messages (no built in math function)

PART B

8. Develop a program to introduce 2D Array manipulation and implement Matrix


multiplication and ensure the rules of multiplication are checked.
9. Develop a Program to compute Sin(x) using Taylor series approximation. Compare
your result with the built- in Library function. Print both the results with appropriate
messages.

9
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

10. Write fiinctions to implement string operations such as compare, concatenate, string
length. Convince the parameter passing techniques.
11. Develop a program to sort the given set of N numbers using Bubble sort.
12. Develop a program to find the square root of a given numberN and execute for all
possible inputs with appropriate messages. Note: Don’t use library function sqrt(n).
13. Implement structures to read, write and compute average- marks and the students
scoring above and below the average marks for a class of N students.
14. Develop a program using pointers to compute the sum, mean and standard deviation
of all elements stored in an array of n real numbers.
15. Implement Recursive functions for Binary to Decimal Conversion.

Conduct of Practical Examination:

 All laboratory experiments, excluding the first, are to be included for practical
examination.

10
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

 Experiment distribution
o For questions having only one part: Students are allowed to pick one
experiment from the lot and are given equal opportunity.
o For questions having part A and B: Students are allowed to pick one
experiment from partA and one experiment from part B and are given equal
opportunity.
 Strictly follow the instructions as printed on the cover page of answer script for
breakup of marks
 Change of experiment is allowed only once and marks allotted for procedure part to
be made zero.
 Marks Distribution (Subjected to change in accordance with university regulations)

a) For questions having only one part — Procedure + Execution + Viva- Voce:
15+70+15 = 100 Marks

b) For questions having partA and B i. PartA- Procedure + Execution + Viva = 4


+ 21 + 5 = 30 Marks ii. Part B — Procedure + Execution + Viva = 10 + 49+ 11 =
70 Marks

11
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

COMPUTER PROGRAMMING LABORATORY


18CPL17

COURSE OUTCOMES

CO1 : Write Algorithms , flowcharts and program for simple problems

CO2 : Correct syntax and logical error to execute a program

CO3 : Write Iterative and wherever possible recursive programs

12
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Demonstrate use of functions, arrays, strings, structures and pointers in


CO4 :
problem solving

COURSE OUTCOMES MAPPING WITH POs AND PSOs


PO PO PO PO PO PO PO PO PO PO1 PO1 PO1 PSO PSO PSO
Cos
1 2 3 4 5 6 7 8 9 0 1 2 1 2 3
CO
2 2 2
1
CO
2 2 3
2
CO
3 3 3 3
3
CO
3 3 3 3
4
Avg
2 2.6 2.6 3 2 2.5 3
.

13
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

1. Familiarization with computer hardware and programming environment, concept of naming the
program files, storing, compilation, execution and debugging, taking any simple C- code.

14
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Description about Functional block diagram of Computer:

A computer is an electronic device, which mainly performs the four functions as reading,
processing, displaying and storing on data. These functions of a computer system can be
carried out by using the three main units namely input unit, system unit and output unit.
The block diagram of a computer system is as follows:

15
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

16
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Fig 1: Block Diagram of a Computer

Notations:
Data and Results flow
Control instructions to other units from control unit ---------------------------------
Instructions from memory unit to control unit --- ----- -- -- -

System or Central Processing Unit (CPU): is commonly known as “processor” that


executes the instructions of a computer program. It has Control Unit (CU) and Arithmetic &
Logical Unit (ALU). These two units perform the basic arithmetic, logical, and input/output
operations.
a) Input unit: is used to enter data and information into a computer. The devices like
keyboard, mouse and scanner are commonly used input devices.
A keyboard is used to enter alphanumeric characters and symbols.
The mouse is used to pick or select a command from the monitor screen.
A scanner is used to scan an image or read a barcode and so on.

17
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

b) Arithmetic and Logic Unit (ALU): is a digital circuit that perform arithmetic (Add,
Sub, Multiplication, Division) and logical (AND, OR, NOT) operations. It helps in fast
computation of scientific calculations on floating-point number.
c) Control unit (CU): is the circuitry that controls the flow of information through the
processor and coordinates the activities of the other units within the processor.
Functions of Control unit
 Accessing data & instructions from memory unit
 Interpreting instructions
 controlling input and output units
 Overall supervision of a Computer system
d) Memory Unit (MU): is the unit where all the input data and results are stored either
temporarily or permanently. The CPU memory is also called as memory register. The
memory of a computer has two types:
a. Main Memory / Primary Memory units
i. Random Access Memory (RAM)
ii. Read Only Memory (ROM)

18
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

b. Secondary Memory / Auxiliary Memory


e) Output Unit: It is used to display or print results from a computer. Monitor, printer and
plotters are commonly used output devices.
f) Bus: A bus is a collection of wires that carries data/Instructions. It connects physical
components such as cables, printed circuits, CPU, Memory, Peripherals etc., for sharing of
Information and communication with one another. The purpose of buses is to reduce the
number of "pathways" needed for communication between the components, by carrying out
all communications over a single data channel.

Types of Buses:
1. System Buses: The system buses are used to transfer the data and instructions
between Main memory (Random Access Memory) and CPU. These are classified
into following three types.

Data Bus Address Bus Control Bus

It is used to transfer the data It is used to transfer the It is used to transfer the
between Processor, Memory addresses of data and control signals between CPU,

19
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

and I/O devices. instructions stored in Memory and I/O devices.


memory.

Bidirectional in nature Unidirectional in nature Unidirectional or


Bidirectional in nature

Fig 2: Types of Buses

20
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

2. I/O Buses: The buses which are used to connect all I/O devices with CPU and
Memory are called I/O buses. These are classified into following three types.

PCI Bus ISA Bus USB Bus


PCI stands for ISA stands for USB stands for
Peripheral Industry Standard Universal Serial Bus
Component Architecture
Interconnect
The motherboard will This is simple and It helps to connect
be having 3 or 4 PCI slowest bus used in various I/O devices
connectors, so that we IBM PCs like keyboard, mouse,
can insert various pen drives, printer, etc.
chips.
Fastest and presently Oldest, simplest and Newest and widely
more powerful bus slowest bus used bus

Main Board or Mother Board: Mother Board is a set of Integrated Chips (ICs) which are
designed to work together. It controls the flow of data/instructions within our computer. It is

21
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

the main board on which other hardware components are connected to enable the computer
system to work as an integrated unit. It consists of sockets, slots, power connectors and bus.
Chip sets: Chip set is the set of integrated chips that are designed to work together. These
set of chips controls the flow of information on computer. The chips may be controllers for
memory, cache, hard drive, key board and peripherals.
Operating System and its types: An Operating System
(OS) is a system software that controls and supervises the
hardware components of a computer system and it
provides the services to computer users. Also called as
Resource Manager that manages the
resources such as CPU, Memory, I/O devices,
Job/Task/Process etc., a computer cannot run without it. The major functions of OS
includes: CPU Management, Memory Management, File Management, Device
Management, Process/Task/Job Management and Security Management.
The primary goal of an OS is to make the computer system convenient and efficient to use.
An OS ensures that the system resources (such as CPU, memory, I/O devices, etc) are
utilized efficiently. For example, there may be many programs residingin the main memory.

22
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Therefore, the system needs to determine which programs are active and which need to wait
for some I/O operation.
Some of the examples of Operating Systems:
 Windows –XP is an O.S. isused for Personal Computers (PCs)
 Unix and XENIX are the OSs used for multi-user computers.
 Windows 7, Windows 8, Macintosh OS, Fedora, and Android, etc.

Types of Operating Systems: The operating systems are classified into 7 types based on
their capability and usage.

Fig 3: Types of OS

23
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

 Batch Processing Tasking OS: The data is collected into a group called batch and
provides only one batch (one after another) of jobs as input to the computer system at a
time. The jobs in a batch are processed on first come first serve basis. In this type, the
process takes place at specified time intervals i.e. weekly or monthly without user
interaction. E.g.Punch cards were using to store the data in batch processing and in payroll
preparation in a business batch processing was helpful.
 Single user and single tasking OS: The OS that allows only one program to execute at a
time is called single user single tasking operating system. Using this operating system user
can do only one task at a time. E.g. DOS (Disk Operating System).
 Single user and multi tasking OS: The OS that allows a single use to perform more than
one task at a time is called single user multi tasking operating system. While working with
the Ms-Word user can perform other work like print a document, listen music.E.g.
Windows-XP, Windows Vista, Windows – 7, etc.
 Multi user and multitasking OS: The O.S. that allows two or more users to use a main
computer system to do more than one task is called multiuser and multitasking operating
system.E.g. Unix is a multiuser and multitasking operating system.

24
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

 Multiprocessing OS : The OS that allows multiple programs to be executed by multiple


CPUs (Processors) is called multiprocessing operating system. Super and main frame
computers have more than one CPU and multiprocessing operating system.
 Real Time Operating System (RTOS): The OS that is used for real time applications
and to carry out certain calculations within the specified time constraint. This OS is used in
applications such as mobile phones, supporting systems in hospitals, nuclear power plants,
oil refining, chemical processing, environmental applications and air-traffic control systems,
disaster management etc.,
 Virtual machine OS: Allows several users of a computer system to operate as if each has
the only terminal attached to the computer.

Basics of Networking & Topology and Network Interface Card(NIC):


Introduction to Computer Network:
A computer network is a collection of computers and devices interconnected to facilitate
sharing of resources among interconnected devices. Advantages of Computer Networks
includeFile Sharing, Resource Sharing, Increased Storage Capacity, Load Sharing and
Facilitate communications.

25
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Computers in a network can be connected by using telephone lines, cables, satellite links,
etc., Wireless network will use radio signals to exchange the information.

Basic components of a computer network: The basic components of a network are as


follows.
1. Protocol: Set of rules used during the data transmission.

26
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

2. Transmission Medium: The media used to connect computer to each other like
telephone lines, twisted pair wire, co-axial cable, fiber optics, satellite signals and radio
signals, etc.
3. Processors: Modem, Multiplexers, bridges, routers, gateways, hub etc. are the processors
used in the network for the flow of data.
4. Channels: Analog/Digital, Synchronous/Asynchronous, Switched/Non switched,
Simplex / duplex, etc.
5. Topology: Physical network layout used for networking. For example, bus topology, star
topology, ring topology, and mesh topology
6. Software: User interface software like Internet Explorer, Netscape Navigator, FTP (File
Transfer Protocol), Telnet (Telecommunication Network), PPP (Point to Point Protocol), and
SMTP (Simple Mail Transfer Protocol) etc.

Types of Networks: The computer networks are mainly classified into 3 types

27
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

LAN MAN WAN

28
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Local Area Network Metropolitan Area Network Wide Area Network


A group of computers that A network which covers A network which covers a
are connected in a small large area like a city large area like a state,
area such as building, country or across a
home, office etc i.e. within continent.
a small campus
Distance covered by this Distance covered by this Distance covered by this
network is less than 1 KM network is 5 to 50 KM. network is 100 to 1000 KM
Used within a single Used by private Used all over the world. i.e.
building like home or organization like cable good example is internet
office television in our city.
Computers are connected A network device called It uses fibre optics, cables
through the twisted pair router is used to connect the and even satellite signals as
cables and co axial cables. LANs together a transmission media.
Transmitting data is Transmitting data is costlier Transmitting data is more
cheaper costlier
Transmission data is Transmission data is Transmission data is
generally error free generally error prone generally error free

29
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Network Topologies: Topology refers to the schematic description of the arrangement of a


network. It is the
actual geometric layout of computers and other devices connected to
the network.
Types of Network Topologies: These are mainly classified into 4
types.
1. Bus Topology:
In this network structure, a single cable runs in a building or campus. All the nodes
(terminals / computers)are connected to this single cable. It is suitable for Local Area
Network.

30
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Advantages:
 Failure of one node will not affect the whole network.
 Well suited for quick setup
 Easy to install and expand
 High rate of data transmission as compare to star and ring topology
Disadvantages:
 A cable break can disable the entire network
 Trouble shouting is very difficult
 Only a single message can travel at a time

2. Ring Topology:
In this network structure, all the computers are connected to each other in the form
of a ring.i.e. first node is connected to second, second to third and so on. Finally
last node is connected to first one.

Advantages:
All the nodes have equal chance to transfer the data
These are easily extensible

31
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

It can span longer distance than other type of networks

Disadvantages:
 Difficult to install
 Expensive
 Difficult to troubleshoot
 Adding or removing computer can disturb the entire network

3. Star Topology:
In this network structure, all the computers are connected with a centralized system called
server. The central computer is also called a hub. To transmit information from one node to
another node, it should be transmitted through a central hub. The central hub manages and
controls all the functions of network.
Advantages:
 Easy to install and expand.
 Addition or deletion of a node is easier.
 Failure of one node will not affect the entire network.

32
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

 Well suited for quick setup


 Easier to debug network problems through a hub
Disadvantages:
 Failure of a central system i.e. hub will affect the whole network
 Cost of hub is expensive.

4. Mesh Topology
In this network structure, all the computers and network devices are interconnected with one
another like a mesh. Every node has a connection to every other node in the network. This
topology is not commonly used for most computer networks because of
its installation difficulty and expensive.

Advantages:
 Failure of a single node will not affect the entire network
 Data transfer rate is very fast because all the nodes are connected to each other.
Disadvantages:

33
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

 Installation and re configuration is very difficult


Costlier

Hybrid Topology: Each of the topologies has their own


advantages and
disadvantages. So in the real world, a pure start or pure ring or bus
is rarely
used. Rather a combination of two or more topologies is used.
Hence, hybrid network topology uses a combination of any two or more
topologies in such a way that the resulting network does not exhibit one of the standard
topologies (e.g., bus, star, ring, etc.). Two very commonly used hybrid network topologies
include the star ring network and star bus network.

Network Interface Cards (NICs): This is the important hardware component, which
connects the machine to the computer network. This will be fixed
into one of the free slot on the mother board. It has one port for the
connection of a network cable. These cards typically use an Ethernet
connection

34
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

and are available in 10, 100, and 1000 Base-T configurations.


A 100 Base-T card can transfer data at 100 Mbps. The cards come
in ISA and PCI versions and are made by companies like 3Com and LinkSys.

Random Access Memory (RAM): RAM is basically main memory of the


computer.
RAM is a semiconductor memory made up of small memory chips that form a
memory module. These modules are installed in the RAM slots on the
motherboard
of computer. Every time you open a program, it gets loaded from the hard drive into
the RAM. This is because reading data from the RAM is much faster than reading data from
the hard drive.

Synchronous Dynamic Random Access Memory (SDRAM): It is an improvement to


standard DRAM because it retrieves data alternately between two sets of memory. This
eliminates the delay caused when one bank of memory addresses is shut down while another
is prepared for reading. It is called "Synchronous" DRAM because the memory is
synchronized with the clock speed that the computer's CPU bus speed is optimized for. The

35
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

faster the bus speed, the faster the SDRAM can be. SDRAM speed is measured in
Megahertz.
FLASH memory: Flash memory is a type of Electrically Erasable Programmable Read-
Only Memory (EEPROM). The name comes from how the memory is designed -- a section
of memory cells can be erased in a single action or in a "flash.". Flash memory cards used
for digital cameras, cellular phones, networking hardware, and PC cards.
Hard disks: Hard disk is prime unit of storage of the computer. Huge amount of data can be
stored and accessed in few milliseconds. The hard disk consists of more number of disks
arranged in the cylindrical order, one above another on a spindle.
The read/write heads are attached to single access mechanism so that
they cannot move independently. All read/write heads are moved
together to position that heads on the required track. The hard disks
available today ranges from 200 GB to 2TB and so on. The present day
hard disk ranges from 3600 rpm to more than 10000 rpm and so on.
Advantages: High storage capacity, high data accessing rate and permanent storage
medium.
Disadvantages: It is not portable.

36
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Optical media: An optical storage media is kind of storage, which is coated with thin metal
on which bits are stored. The data can be stored in to optical storage media or read form the
optical storage media.
 The devices which perform read or write operation on optical storage media are called
optical storage media.
 The laser technology is used to read the data or write the data on optical storage devices.

Examples: CD-ROM, DVD etc.


Compact Disc Read-Only-Memory (CD-ROM): It is a type of optical disc that uses laser
technology to read and write data on the disc. The information stored on CDROM becomes
permanent and cannot be altered. This means that the stored information can only be read
for processing.
A CD-ROM uses the round shaped optical disk to store data, applications, games and audio
files. It can store up
to 700 MB of data. It has become integral part of every organization due to its
features like reliability, reasonable, storage capacity and easy to use of carry.

37
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

CD-Drive will be with motor to rotate the disks to perform read and write operations. A CD-
drive will consists of the components like Disc drive, disk drive motor, laser pick up
assembly tracking drive and tracking motor and so on.

Compact Disk Recordable (CD-R): The CD-R allows you to create your own CD.CD-R
drives have the ability to create CDs but they can write data on the disk only once.CD-R
technology also called as Write Once-Read much (WORM) technology. Laser technology is
used to write the data on the compact disk.CD-R drives come in IDE, SCSI and USB
models.
Compact Disc Rewritable (CD-RW): CD-RW is an erasable optical disk which is used to
write data multiple times on a disk, CD-RW disks are good for data backup, data archiving
or data distribution on CDs. The disk normally holds 700MB of data. Technology to write
data multiple times on a CD was known as the Phase change Dual (PD) technology. The
reflective properties of a CD-RW are different than regular CD-ROM disks.
Digital Video Disk or Digital Versatile Disc (DVD-ROM): A DVD is a small optical disk
having high density medium and capable of storing a full-length movie on a single disk. The
high density is achieved by using both sides of the disk, special data-compression
technology, and extremely small tracks to store the data.

38
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Advantages: Storage capacity is more compared to CDs.


Flash Drives (Pen drives): USB flash drives are removable, rewritable, and physically
much smaller drives weighing even less than 30 g. A flash drive consists of a small printed
circuit board carrying the circuit elements and a USB connector,
insulated electrically and protected inside a plastic, metal, or
rubberized case which can be carried in a pocket or on a key
chain.

Advantages
 Data stored on flash drives is impervious to scratches and dust
 Mechanically very robust
 Easily portable
 Have higher data capacity than any other removable media.
 Compared to hard drives, flash drives use little power
 Flash drives are small and light-weight devices
 Flash drives can be used without installing device drivers.

39
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Disadvantages
 Can sustain only a limited number of write and erase cycles before the drive fails.
 Most flash drives do not have a write-protect mechanism
 Flash drives are very small devices that can easily be misplaced, left behind, or otherwise
lost.
 The cost per unit of storage in a flash drive is higher than that of hard disks

Keyboard: A keyboard is the primary input deviceused in all computers. Keyboard has a
group of switches resembling the keys on an ordinary typewriter machine. Normally
keyboard has around 101 keys. The keyboard includes key that allows us to type letters,
numbers and various special symbols such as *, /, [ , % etc.
Mouse: The mouse is the key input device to be used in a Graphical User Interface (GUI).
The users can use mouse to handle the cursor pointer easily on the screen to perform various
functions like opening a program or file.
With mouse, the users no longer need to memorize commands, which was earlier a necessity
when working with text-based command line environment such as MS-DOS.

40
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Advantages:
 Easy to use; Cheap; Can be used to quickly place the cursor anywhere on the screen
 Helps to quickly and easily draw figures
 Point and click capabilities makes it unnecessary to remember certain commands

Disadvantages:
 Needs extra desk space to be placed and moved easily
 The ball in the mechanical mouse needs to be cleaned very often for smooth movements

Printers: The printer is an output device, which is used to get hard copy of the text
displayed on the screen. The printer is an external optional device that is connected to the
computer system using cables. The printer driver software is required to make the printer
working. The performance of a printer is measured in terms of Dots Per Inch (DPI) and
Pages Per Minute (PPM) produced by the printer.

Types of Printers:

41
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

1) Impact Printers: Impact printers are those printers in which a physical contact is
established between the print head, ribbon (cartridge) and paper. E.g. Dot Matrix Printers
2) Non-Impact Printers: No physical contact is established between the print head, ribbon
(cartridge) and paper .E.g. Inkjet Printers and Laser Printer
Dot matrix, Inkjet and Laser printers

Sl. Dot Matrix Printer Inkjet Printer Laser Printer


No.

1 Impact Printer Non-impact Printer Non-impact printer

2 It uses metal pins in its Its print head does not have The laser printer uses a
head to create text and metal pins; instead it has beam of laser for printing.
graphics in the form of several tiny nozzles that spray
dots. ink onto the paper. Each
nozzle is thinner than hair.

42
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

3 The process of printing The ink cartridges are The printer uses a
involves striking a pin attached to the printer head cylindrical drum, a toner
against a ribbon to that moves horizontally from and the laser beam.
produce its output. left to right.

4 Printing speed is slower Printing speed is slower than Printing speed is higher
than laser printer, laser dot matrix. than both.

5 Character by character Line by line printing It is a page printer


printing

6 Low quality printing High quality printing High quality printing

7 Less expensive High expensive High expensive

8 Generates much noise Generates less noise while No noise


while printing printing

9 Speed is measured in Speed is measured in CPI Speed is measured in PPM

43
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

DPI (Dots Per Inch) (Characters Per Inch) (Pages Per Minute)

10 Monochrome (Black & Colour printer Monochrome and colour


White) Printers printer

11

Plotters: A plotter is similar to printer that produces hard-copy output with high-
quality colour graphics. Plotters are generally more expensive than printers,
ranging from about $1000 to $75000.

Programming environment:

44
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Operating System Application


Windows Turbo c application or any other IDE
Linux Terminal

Basic C Program Structure:

#include <stdio.h>
void main()
{
printf("Hello, World!");
}

Steps for writing and executing a C program(in windows):


1. Open Turbo C/C++ application

2. File->New
45
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

3. Type the program


4. Save the file File->Save or F2 with the file extension as .c
5. To compile the program Compile->Compile(Alt+F9)
6. To run the program Run->Run(Ctrl+F9)

PART A

2. Develop a program to solve simple computational problems using arithmetic


expressions and use of each operator leading to simulation of a commercial calculator. (No
built-in math function)

#include<stdio.h>

#include<conio.h>

void main()

float a,b,res;

46
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

char op;

clrscr();

printf("Enter an Expression (eg:1+6): ");

scanf("%f %c %f",&a,&op,&b);

switch(op)

case '+' : res=a+b;

break;

case '-' : res=a-b;

break;

case '*' : res=a*b;

47
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

break;

case '/' : if(b==0)

printf("Arthimetic Exception:Cannot Divide a number by


0.");

getch();

return;

else

res=a/b;

48
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

break;

case '%' : res= (int)a % (int)b;

printf("%g %c %g = %g \n",a,op,b,res);

getch();

Output

49
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

3. Develop a program to compute the roots of a quadratic equation by accepting the


coefficients. Print appropriate messages.

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main( )

float a,b,c,disc,root1,root2,real,imag;

clrscr();

printf("Enter a,b,c values \n");

scanf("%f%f%f",&a,&b,&c);

disc =b*b - 4*a*c;

50
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

if( (a==0) && (b==0) )

printf("Invalid co-efficients \n");

else if(a==0)

printf("Linear equation \n");

root1= - c / b;

printf("Root=%f",root1);

else if(disc==0)

51
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

printf("The roots are Real and Equal \n");

root1= - b / (2*a);

root2= - b / (2*a);

printf("Root1=%f \n Root2=%f \n",root1,root2);

else if(disc>0)

printf("The roots are Real and distinct \n");

root1=( - b + sqrt(disc) ) / (2*a);

root2=( - b - sqrt(disc)) / (2*a);

52
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

printf("Root1=%f \n Root2=%f \n",root1,root2);

else

printf("The roots are Real and Imaginary \n");

real=- b / (2*a);

imag=sqrt( fabs ( disc ) ) / (2*a);

printf("Root1=%f + i %f \n",real,imag);

printf("Root2=%f - i %f \n",real,imag);

getch();

53
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Output

4. Develop a program to find the reverse of a positive integer and check for palindrome or
not. Display appropriate messages.

54
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

#include<stdio.h>

#include<conio.h>

void main()

long int temp,rev=0,i,num,remainder;

clrscr();

printf("Enter the number \n");

scanf("%ld",&num);

temp=num;

while(num!=0)

55
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

remainder=num%10;

num=num/10;

rev=rev*10+remainder;

printf("The reverse of the number is %ld\n",rev);

if(rev==temp)

printf("%ld is a palindrome \n",temp);

else

printf("%ld is not a palindrome \n",temp);

getch();

56
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Output

5. An electricity board charges the following rates for the use of electricity: for the first 200
units 80 paise per unit: for the next 100 units 90 paise per unit: beyond 300 units Rs 1 per
unit. All users are charged a minimum of Rs. 100 as meter charge. If the total amount is
more than Rs 400, then an additional surcharge of 15% of total amount is charged. Write a
program to read the name of the user, number of units consumed and print out the charges.

#include<stdio.h>

#include<string.h>

#include<conio.h>

57
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

void main()

{ int unit;

float charge,surcharge=0, amt,total_amt;

char name[25];

clrscr();

printf("\nEnter the customer Name: ");

scanf("%s",name);

printf("Enter the unit consumed by customer: ");

scanf("%d",&unit);

if (unit <=200 )

charge = 0.80;

58
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

else if (unit>200 && unit<=300)

charge = 0.90;

else if (unit>300)

charge = 1.00;

amt = unit*charge;

if (amt>400)

surcharge = amt*15/100.0;

total_amt = amt+surcharge;

if (amt < 100)

total_amt =100;

printf("\nElectricity Bill\n");

59
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

printf("Customer Name: %s",name);

printf("\nAmount Charges @Rs. %4.2f per unit :\t


%8.2f",charge,amt);

printf("\nSurchage Amount :\t


%8.2f",surcharge);

printf("\nNet Amount to be paid by the Customer :\t


%8.2f",total_amt);

getch(); }

Output

60
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

6. Introduce 1D Array manipulation and implement Binary search. Implement using


functions to check whether the given number is prime and display appropriate messages.
(No built-in math function)

#include<stdio.h>

#include<string.h>

void main()

61
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

char name[10][20],key[10];

int i,n,low,high,mid,found=0;

clrscr();

printf("Enter the number of names to be read:");

scanf("%d",&n);

fflush(stdin);

printf("Enter %d names in ascending order:\n",n);

for(i=0;i<n;i++)

gets(name[i]);

printf("Enter the name to be searched:");

gets(key);

62
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

low=0;

high=n-1;

while(low<=high && !found)

mid=(low+high)/2;

if(strcmp(key,name[mid])==0) found=1;

if(strcmp(key,name[mid])>0) low=mid+1;

if(strcmp(key,name[mid])<0) high=mid-1;

if(found==0)

63
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

printf("Key not found:\n");

else

printf("Key found at position %d \n",mid+1);

getch();

Output

64
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

7. Implement using functions to check whether the given number is prime and display
appropriate messages (no built in math function)

#include<stdio.h>

#include<conio.h>

int isPrime(int);

void main()

int res,num;

clrscr();

printf("Enter the number:");

scanf("%d",&num);

65
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

res=isPrime(num);

if(res==0)

printf("%d is not a Prime Number\n",num);

else

printf("%d is a Prime Number\n",num);

getch();

int isPrime(int num)

int i;

if(num==0 || num==1)

66
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

return 0;

for(i=2;i<=num/2;i++)

if(num %i == 0 )

return 0;

return 1;

67
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Output

PART B

68
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

8. Develop a program to introduce 2D Array manipulation and implement Matrix


multiplication and ensure the rules of multiplication are checked.

#include<stdio.h>

#include<conio.h>

void main()

int a[5][5],b[5][5],c[5][5],m,n,p,q,i,j,k;

clrscr();

printf("Enter the size of first matrix \n");

scanf("%d%d",&m,&n);

printf("Enter the size of second matrix \n");

scanf("%d%d",&p,&q);

69
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

if(n==p)

printf("Enter the elements of first matrix \n");

for(i=0; i<m; i++)

for(j=0; j<n; j++)

scanf("%d",&a[i][j]);

printf("Enter the elements of the second matrix \n");

70
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

for(i=0; i<p; i++)

for(j=0; j<q; j++)

scanf("%d",&b[i][j]);

printf("First matrix \n");

for(i=0; i<m; i++)

for(j=0; j<n; j++)

71
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

printf("%d\t",a[i][j]);

printf("\n");

printf("Second matrix \n");

for(i=0; i<p; i++)

for(j=0; j<q; j++)

printf("%d\t",b[i][j]);

72
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

printf("\n");

for(i=0; i<m; i++)

for(j=0; j<q; j++)

c[i][j]=0;

for(k=0; k<n; k++)

c[i][j]=c[i][j]+a[i][k]*b[k][j];

73
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

printf("The product of two matrix is \n");

for(i=0; i<m; i++)

for(j=0; j<q; j++)

printf("%d \t",c[i][j]);

printf("\n");

74
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

else

printf("Multiplication is not possible \n");

getch();

Output

75
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

76
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

9. Develop a Program to compute Sin(x) using Taylor series approximation. Compare


your result with the built- in Library function. Print both the results with appropriate
messages.

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

77
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

int i,n;

float degree,x,term,sum;

clrscr();

printf("Enter the value in degree's : ");

scanf("%f",&degree);

printf("Enter number of terms in the series : ");

scanf("%d",&n);

x=degree*3.142/180;

term=x;

sum=term;

for(i=3;i<=n;i=i+2)

78
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

term=-term*x*x/((i-1)*i);

sum=sum+term;

printf("MYSIN(%g)=%f \n",degree,sum);

printf("Using built-in librabry function, SIN(%g)=%f


\n",degree,sin(x));

getch();

Output

79
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

10. Write fiinctions to implement string operations such as compare, concatenate, string
length. Convince the parameter passing techniques.

#include<stdio.h>

#include<conio.h>

int my_strlen(char[]);

80
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

int my_strcmp(char[],char[]);

void my_concat(char[],char[]);

void main()

int op,res;

char str1[26],str2[26];

clrscr();

printf("1.Compare \n2.Concatenate \n3.String Length \nEnter


the option:");

scanf("%d",&op);

fflush(stdin);

switch(op)

81
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

case 1: printf("Enter String1:");

gets(str1);

fflush(stdin);

printf("Enter String2:");

gets(str2);

res=my_strcmp(str1,str2);

if(res==0)

printf("%s is equal to %s\n",str1,str2);

else if(res>0)

printf("%s is greater than %s \n",str1,str2);

82
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

else printf("%s is less than %s \n",str1,str2);

break;

case 2: printf("Enter String1:");

gets(str1);

fflush(stdin);

printf("Enter String2:");

gets(str2);

fflush(stdin);

my_concat(str1,str2);

break;

case 3: printf("Enter the String:");

83
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

gets(str1);

res=my_strlen(str1);

printf("Length of \"%s\" is %d \n",str1,res);

getch();

int my_strlen(char str1[])

int i=0;

while(str1[i] != '\0') i++;

return i;

84
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

int my_strcmp(char str1[],char str2[])

int i=0;

while(str1[i]==str2[i])

if(str1[i]=='\0') break;

i++;

return str1[i]-str2[i];

85
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

void my_concat(char str1[],char str2[])

int i=0,j=0;

while(str1[i]!='\0') i++;

while(str2[j]!='\0')

str1[i++]=str2[j++];

str1[i]='\0';

puts(str1);

86
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

Output

87
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

11. Develop a program to sort the given set of N numbers using Bubble sort.

#include<stdio.h>

#include<conio.h>

void main()

int a[30],i,j,n,temp;

clrscr();

printf("Enter number of elements : ");

scanf("%d",&n);

printf("Enter %d elements : ",n);

for(i=0;i<n;i++)

88
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

scanf("%d",&a[i]);

printf("Before sorting the elements :");

for(i=0;i<n;i++)

printf("%d ",a[i]);

for(j=1;j<n;j++)

for(i=0;i<n-j;i++)

89
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

if(a[i]>a[i+1])

temp=a[i];

a[i]=a[i+1];

a[i+1]=temp;

printf("\nAfter sorting the elements :");

for(i=0;i<n;i++)

90
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

printf("%d ",a[i]);

getch();

Output

91
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

12. Develop a program to find the square root of a given numberN and execute for all
possible inputs with appropriate messages. Note: Don’t use library function sqrt(n).

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

int i;

float n,x,root;

clrscr();

92
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

printf("Enter the Number : ");

scanf("%f",&n);

if(n<0)

printf("Invalid Input\n");

else

x=1.0;

for(i=1;i<=30;i++)

93
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

root=( (x*x)+n ) / (2*x);

x=root;

printf("The Square Root of %f is %f \n",n,root);

printf("Using Built-In Library function,Square Root of %f is


%f\n",n,sqrt(n));

getch();

Output

94
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

13. Implement structures to read, write and compute average- marks and the students
scoring above and below the average marks for a class of N students.

#include<stdio.h>

#include<conio.h>

struct student

int roll;

95
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

char name[50];

int marks;

};

void main()

struct student s[10];

int i,n,sum=0;

float average=0.0;

clrscr();

printf("\nEnter the number of students:");

scanf("%d",&n);

96
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

fflush(stdin);

for(i=0;i<n;i++)

printf("Enter the details of student %d\n",i+1);

printf("Enter the roll number:");

scanf("%d",&s[i].roll);

fflush(stdin);

printf("Enter the Name:");

gets(s[i].name);

fflush(stdin);

printf("Enter Total Marks:");

97
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

scanf("%d",&s[i].marks);

fflush(stdin);

printf("\n");

for(i=0;i<n;i++)

sum=sum+s[i].marks;

average=(float)sum/n;

printf("Class Average is %g\n",average);

98
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

printf("-------------------------------------\n");

printf("Record details of students:\n");

printf("\nRollNo\t Student Name\t Total_Marks\t


Above_Average(Y/N) \n");

printf("------------------------------------\n");

for(i=0;i<n;i++)

printf("%4d",s[i].roll);

printf("%15s",s[i].name);

printf("%15d",s[i].marks);

if(s[i].marks>=average)

printf("\tYes");

99
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

else

printf("\tNo");

printf("\n");

getch();

Output

100
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

101
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

14. Develop a program using pointers to compute the sum, mean and standard deviation
of all elements stored in an array of n real numbers.

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

102
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

float a[10],*ptr, mean, std, sum=0,sumstd=0;

int n, i;

clrscr();

printf("Enter the no. of elements\n");

scanf("%d", &n);

printf("Enter the array elements\n");

for(i=0; i<n; i++)

scanf("%f",&a[i]);

103
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

ptr=a;

for(i=0; i<n; i++)

sum=sum+*ptr;

ptr++;

mean=sum/n;

ptr=a;

for(i=0; i<n; i++)

sumstd=sumstd+pow((*ptr-mean),2);

104
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

ptr++;

std=sqrt(sumstd/n);

printf("Sum=%.3f\t",sum);

printf("Mean=%.3f\t",mean);

printf("Standard Deviation=%.3f\t",std);

getch();

Output

105
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

15. Implement Recursive functions for Binary to Decimal Conversion.

#include <stdio.h>

#include<conio.h>

int convert(int);

void main()

int dec, bin;

clrscr();

106
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

printf("Enter a Binary number: ");

scanf("%d", &bin);

dec = convert(bin);

printf("The Decimal Equivalent of %d is %d \n", bin, dec);

getch();

int convert(int bin)

if (bin == 0)

return 0;

107
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

else

return (bin % 10 + 2 * convert(bin / 10));

Output

108
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

109
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

110
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

VIVA-VOCE
QUESTIONS

111
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

1) What is a Computer?

2) What is CPU?

3) What is ALU?

112
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

4) What is CU?

5) What is RAM?

6) What is ROM?

7) What is PROM?

8) What is EPROM?

9) What is EEPROM?

10) Differentiate between Volatile and non-volatile memory.

11) What are the input and output devices?

12) What is the need for cache memory?

13) Differentiate between main memory and second memory.

14) What is hardware?

15) Mention the different types of hardware components?

113
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

16) What are the different types of keyboards?

17) Differentiate between serial and parallel keyboard.

18) How do you classify printers?

19) Differentiate between serial and parallel printer.

20) Differentiate between impact and non-impact printers.

21) Differentiate between line and page printers.

22) Which printer do you select when high quality output is to be produced?

23) What is meant by softcopy output?

24) What is meant by hardcopy output?

25) What is printer buffer?

26) What is meant by tracks?

27) What is meant by sectors?

114
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

28) What is CD-ROM?

29) What are the different types of mouse?

30) What are the main parts of a floppy disk?

31) Differentiate between magnetic disks and optical disks.

32) What is programming?

33) What is software?

34) What are the different types of software?

35) What are the different types of programming languages?

36) Differentiate between interpreter and compiler.

37) Differentiate between loader and linker.

38) Differentiate between Application software and System software.

39) What is an operating system?

115
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

40) What are language processors?

41) Mention some operating systems.

42) Differentiae between compiler and assembler.

43) What is translator?

44) What is meant by interpretation?

45) What is meant by source program?

46) What is meant by object program?

47) Give examples for High Level Languages.

48) Give examples for Assembly Level Languages.

49) Give examples for General purpose HLL.

50) Give examples for Specific purpose HLL.

51) Differentiate between Analog and Digital computers.

116
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

52) Differentiate between microcomputer & minicomputer.

53) Differentiate between internal & external DOS commands.

54) How do you classify the computers based on the size & capability?

55) How do you classify the computers based on principle of working?

56) What is computer network?

57) How do you classify the computer networks?

58) What is Batch processing?

59) What is Time Sharing?

60) Differentiate between LAN and WAN.

61) What are the different types of DOS?

62) What is DOS?

63) What is Real Time Systems?

117
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

64) What are the advantages of computer network?

65) What is BCPL?

66) Who developed BCPL?

67) Who developed B language?

68) Who developed C language?

69) How do you make comments in C program?

70) How the name C is derived?

71) What is K & R C?

72) What is preprocessor statement?

73) Differentiate between constant and variable.

74) What is data type?

75) Name the basic data types of C.

118
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

76) Differentiate between string constant and character constant.

77) What is the range of integer, char, float for a 16-bit computer?

78) What is a statement?

79) What is a keyword?

80) Differentiate between keywords and identifiers.

81) What is the need for an escape sequences?

82) What is a symbolic constant?

83) How do you classify C operators?

84) What is the use of modulus operator?

85) What is meant by mixed mode operation?

86) What are bitwise operators?

87) What is unary operator?

119
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

88) What is binary operator?

89) What is typecasting?

90) What is a conditional / ternary operator?

91) What is need for type conversion?

92) Differentiate between && and &.

93) Differentiate between pre-increment/decrement & post-increment/decrement.

94) Differentiate between Unformatted and formatted i/o statements.

95) How do you classify the control statements?

96) Differentiate between while and do-while loop.

97) Differentiate between break and continue.

98) When do you prefer for loop statement?

99) What is looping?

120
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

100) What is an array?

101) Give the classification of arrays?

102) Differentiate between an array and an ordinary variable.

103) Array variable is also called as ______.

104) What are character arrays?

105) When do you use two-dimensional character array?

106) Name the different string handling functions?

107) What is meant by modularization?

108) Differentiate between standard functions & user-defined functions?

109) Differentiate between arguments and parameters.

110) Differentiate between local and global variables.

111) Name the different methods of parameter passing?

121
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING
COMPUTER
PROGRAMMING
(18CPL17)

112) How does the function definition differ from function declaration?

113) What is recursive function?

114) What is meant by scope of a variable?

122
1ST SEM, COMPUTER SCIENCE & VVCE, MYSURU-570002
ENGINEERING

Das könnte Ihnen auch gefallen