SlideShare a Scribd company logo
1 of 174
COMPUTER
CONCEPTS
AND FUNDAMENTALS OF
PROGRAMMING
Ganesh B. Ingle, Vishwanath Mishra, Ms. G. Sridevi Devasena,
Smt. Unnati Nitin Chaudhari, Wallace Jacob
M A L AY S I AS I N G A P O R EI N D I A
Notion Press
Old No. 38, New No. 6
McNichols Road, Chetpet
Chennai - 600 031
First Published by Notion Press 2018
Copyright © Ganesh B. Ingle, Vishwanath Mishra,
G. Sridevi Devasena, Unnati Nitin Chaudhari,
Wallace Jacob 2018
All Rights Reserved.
ISBN 978-1-644291-23-8
This book has been published with all efforts taken to make the material error-free after the consent of the author.
However, the author and the publisher do not assume and hereby disclaim any liability to any party for any loss,
damage, or disruption caused by errors or omissions, whether such errors or omissions result from negligence,
accident, or any other cause.
No part of this book may be used, reproduced in any manner whatsoever without written permission from the
author, except in the case of brief quotations embodied in critical articles and reviews.
Preface
We will remain indebted to the luminaries of the ilk of Wilhelm Schickard, Blaise Pascal, Guglielmo Marconi, Samuel F. B. Morse,
Nikola Tesla, Charles Babbage, Lady Ada Lovelace, John von Neumann, Alan Turing, Grace Hopper, Edsger W. Dijkstra, Claude
Shannon, Edgar F. Codd, Dennis Ritchie, Bjarne Stroustrup, Vint Cerf, Tim Berners-Lee, Sergey Brin, Larry Page, Steven Paul
Jobs, and their like, who framed and changed the landscape of electronics, telecommunications and computing forever. We are also
thankful to Vijay Mukhi (and his team), Yashvant Kanetkar whose books on BASIC, C, C++, UNIX, and JAVA, explored acres
and acres of uncharted territory. We feel that their contribution cannot be measured. We have drawn inspiration from them and
hence written this book.
This book is a humble endeavor on our part to help the IMU Marine Engineering and Nautical Science students appreciate and
comprehend the very important subject: Computer Science. Indubitably ‘computer science and technology’ has invaded and
pervaded our lives and the best course of action would be to understand it and use it for the benefit of every living and non-living
being.
As frail human beings, we might be lacking in many spheres. However, we are open to constructive criticism and humbly solicit
suggestions for improvement of the text from the esteemed readers of our book.
CONTENT
	 Chapter – 1 1
		 INTRODUCTION TO COMPUTER
	 Chapter – 2 11
		 COMPUTER SOFTWARE
	 Chapter – 3 18
		 INTRODUCTION
	 Chapter – 4 24
		 DATA TYPES AND OPERATORS
	 Chapter – 5 35
		 DECISION CONTROL INSTRUCTIONS
	 Chapter – 6 46
		 DECISION MAKING AND LOOPING
	 Chapter – 7  59
		 ARRAYS
	 Chapter – 8  75
		 STRINGS
	 Chapter – 9  79
		 USER DEFINED FUNCTIONS
	 Chapter – 10  83
		 POINTERS
	 Chapter – 11  89
		 STRUCTURES AND UNIONS
	 Chapter – 12  148
		 ELECTRONIC COMMERCE
Chapter – 1
INTRODUCTION TO COMPUTER
1.1  Computer Introduction
It is an electronic device capable of performing complex arithmetical and logical operations to give desired output.
1.1.1  Characteristics of Computer are as follows:
•	 Speed
•	 Arithmetical and Logical Operations
•	 Accuracy
•	 Reliability
•	 Storage
•	 Retrieving Data and Program
•	 Automation
•	 Versatility (Flexible)
•	 Consistency
•	 Communications
1.1.2 Hardware/Software
Computer Hardware
Parts of computer, which can be touch is called hardware.(Physical Parts)
•	 Monitor
•	 CPU
•	 Key Board
•	 Mouse
•	 Speaker
Computer Software
Parts of computer, which cannot be touch is called software. These are set of instructions or programs written in any
computer programming language.
Operating System Software: Windows, MAC, Linux
Application Software: MS Office, Photoshop, Media Player
Internet Browser Software: Internet Explorer, Google Chrome, Mozilla Firefox, etc.
Computer Concepts and Fundamentals of Programming
2
1.1.3  Generations of computer
i.	 First(1945-1955): Used vacuum tubes. Were very large. Generated immense heat. Very expensive.
ii.	 Second(1955-1965):Used transistors. Continued to be large andexpensive.
iii.	 Third(1965-1975):Used integrated circuits. Significant reduction in size and cost
iv.	 Fourth(1975-1995): Uses Very Large Scale Integration. Desktop computers would not have been possible without
VLSI. It used Microprocessor minimizing the size of P.C.
v.	 Fifth: Will provide us with Artificial intelligence. Also called knowledge information processing system
Fig: Generations of computer
1.2  Classification of Computers
Computers are classified depending upon the types of electronics/hardware and processing power
Depending on hardware they are classified in to
•	 Analog,
•	 Digital and
•	 Hybrid
Depending on processing power and speed they are classified in to
Personal computer
•	 A single-user computer
•	 Can be useful at School, Home, etc.
•	 Known as Micro Computer
•	 Laptop, Desktop
Workstation
•	 A powerful, single-user computer.
•	 A workstation is like a personal computer, but it has a more powerful microprocessor
•	 higher-quality monitor.
•	 Can be found in companies etc.
Minicomputer
•	 A multi-user computer
•	 Capable of supporting from 10 to hundreds of users simultaneously.
•	 Can be found in banks, government departments etc.
Introduction to computer
3
Mainframe
•	 A powerful multi-user computer
•	 Capable of supporting hundreds or thousands of users simultaneously.
Supercomputer
•	 An extremely fast computer
•	 Can perform hundreds of millions of instructions per second
•	 Weather, scientific research can be done by these types of computer
1.3  Basic internet terminology
Host
A computer that is used to transfer data on the Internet.
Web Hosting
To store and make web pages available and ready for inquiries, or a computer that has a consistent connection to the
Internet.
Domain
A domain name is a description or representation of a computer's location on the Internet. It is usually separated by a
dot.
For example:
http://www.imu.edu.in
DNS
DNS (Domain Name System) is a large database of domain names and their correspondent Internet (IP Addresses).
IP address
This 32 bit address mechanism for addressing the devices on the network. Different classes of IP address as per the IPV4
standard are as follows:
i.	 Class A –(0-126)
ii.	 Class B-(128-191)
iii.	 Class C-(192-223)
iv.	 Class D-(224-239)
v.	 Class E-(240-255)
The 127 is used by the local host as loop back adapter and for the inter processes communication. In the above list class
D and E are used for the experimental purpose.
HTML
Hypertext Markup Language is a coding language used to tell a browser how to place pictures, text, multimedia and
links to create a web page.
FTP
File Transfer Protocal is a method of transferring files between two computers on the Internet
InterNic
InterNic is governs and maintains the name and host registration on the Internet.
Computer Concepts and Fundamentals of Programming
4
URL
Uniform Resource Locator is a web address used to connect website on the World Wide Web.
For example:
http://www.imu.edu.in
Port
The total nober of ports are 0-65535.A a Port is a channel that a server software would listen to, for any inquiries.
Bit
Bit is a single digit base 2. For example: 1 is a bit or 0 is a bit.
Byte
A Byte generally consists of eight bits.
Server
The server computer coupled with server software, listens for inquiries from a client computer.
Upload
To upload is to transfer data from your computer to another computer.
Download
To download is to transfer data from another computer to your computer.
sss
1.4  Basic computer organization
Following points are important points as far as computer organization is concern
Fig: CPU and main memory
•	 Processor system and its operations: Data Movement Operations. It is moving data from memory to the CPU It
is moving data from memory to memory. It performs all input and output. Arithmetic and Logical Operations. It
performs all integer arithmetic. It compares two quantities shifting, rotating bits in a quantity, testing, comparing,
and converting bits
•	 CPU: manages the instruction-execution cycle. FETCH – DECODE – EXECUTE. Coordinates the activities
of other devices. Different types of CPU operations are, starting a program Halting a program, skipping to other
instructions, testing data to decide whether to skip over some instructions.
Introduction to computer
5
Fig: inside CPU
•	 Memory: (fast access) storage device for preserving binary data and instructions. Memory is divided into units or
words. Each is usually a standard size or fixed-length. Each memory word has a unique address for random access.
It has two types RAM and ROM. Random Access Memory (RAM). It is readable, writeable, usually volatile
(e.g., Dynamic RAM or DRAM) used as general storage. ROM is Read Only Memory (ROM).It is readable,
permanent, nonvolatile,Special-purpose storage for data and instructions.
•	 Input/output system
•	 Input/output devices
•	 Secondary storage
i.	 Main memory is organization
ii.	 Types of instructions for a typical processor
iii.	 Scale and performance factors
1.5  Number systems
The “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. There are different types of number systems depending upon the base or radix. There are different
types of number systems are as follows:
•	 Binary (radix=2): 1000111101 (radix = 2)
•	 Ternary (radix=3): 0 to 3
•	 Octal (radix=8): 0 to 7
•	 Decimal (radix=10): 0 to 9
•	 Hexadecimal (radix=16): 0 to 9 and A, B, C, D, E, F
•	 BCD, EBCD, Excess3, BCO(Binary Coded Octal), BCH(Binary Coded Hexadecimal)
•	 Binary, octal, decimal and hexadecimal are called positional number system
Computer Concepts and Fundamentals of Programming
6
1.5.1  Decimal to binary conversion:
	 1)	(37)10
= (100101)2
	
q r
2 37 1
2 18 0
2 9 1
2 4 0
2 2 0
2 1 1
2 0
	 2)	(41.68755)10
= (101001.1011)2
	
q r
2 41 1
2 20 0
2 10 0
2 5 1
2 2 0
2 1 1
2 0
Note: conversion from radix 10 to any base –r system similar to the above example only 2 will replaced by r
1.5.2  Decimal to Octal Conversion
	(153.153)10
= (231.406517)8
	
q r
8 19 1
8 2 3
8 0 2
1.5.3  Decimal to Hexadecimal Conversion
	(253)10
= (FD)16
	
q r
16 253 13(D)
16 15 15(F)
100101
101001
0.68755 × 2 = 1.3750
0.3750 × 2 = 0.7500
0.7500 × 2 = 1.5000
101
231
0.153 × 8 = 4.104
0.104 × 8 = 0.832
0.832 × 8 = 6.656
0.656 × 8 = 5.248
0.248 × 8 = 1.984
0.984 × 8 = 7.872
0.406517
FD
Introduction to computer
7
1.5.4  Binary to Decimal Conversion
(101101)2
= 25
× 1+24
× 0 +23
× 1 + 22
× 1 + 21
× 1 + 20
× 1
(101101)2
= 32 + 8 + 4 + 1 = (45)10
1.5.5  Binary to Hexadecimal conversion
(1100101001010010)2
= (CA52)16
i.	 First, split the binary number into groups of four digits, starting with the least significant digit.
ii.	 Next, convert each group of four binary digits to a single hex digit.
iii.	 Put the single hex digits together in the order in which they were found, and you’re done!
1100 1010 0101 00102
C A 5 2
1.5.6  Hexadecimal to Decimal Conversion
A hexadecimal number can be converted into its equivalent number in decimal system by calculating the sum of the products of
each symbol multiplied by its corresponding place value.
Examples
(6B39)16
= (27449)10
(6 × 163
) + (11 × 162
) + (3 × 161
) + (9 × 160
)
= 24567 + 2816 +48 + 9
= 27449
1.5.7  Octal to Decimal conversion
An octal number can be converted into its equivalent number in decimal system by calculating the sum of the products of each
digit multiplied by its corresponding place value.
(13256)8
= (5806)10
into its equivalent in decimal systems
(1 × 84
) + (3 × 83
)+(2 × 82
) + (5 × 81
)+(6 × 80
)
= 4096 + 1536 + 128 + 40 + 6
= 5806
1.5.8  Octal to Hexadecimal conversion
The given octal number can be converted into its equivalent hexadecimal number in two different steps:
i.	 Convert the given octal number into its binary equivalent by representing each digit in the octal number to its equivalent
3-bit binary number.
ii.	 Divide the binary number into 4-bit sections starting from the least significant bit
Example: (365)8
= (F5)16
3 6 5
011 110 101
0000 1111 0101
0 F 5
}
}
}
}
Computer Concepts and Fundamentals of Programming
8
1.5.9  Binary coded decimal
The BCD system is employed by computer systems to encode the decimal number into its equivalent binary number. This is
generally accomplished by encoding each digit of the decimal number into its equivalent binary sequence. The main advantage of
BCD system is that it is a fast and efficient system to convert the decimal numbers into binary numbers as compared to the pure
binary system. The 4-bit BCD system is usually employed by the computer systems to represent and process numerical data only.
In the 4-bit BCD system, each digit of the decimal number is encoded to its corresponding 4-bit binary sequence. The two most
popular 4-bit BCD systems are:
•	 Weighted 4-bit BCD code
•	 Excess-3 (XS-3) BCD code
1.5.10 EBCDIC
The EBCDIC code is an 8-bit alphanumeric code that was developed by IBM to represent alphabets, decimal digits and special
characters, including control characters. The EBCDIC codes are generally the decimal and the hexadecimal representation of
different characters. This code is rarely used by non IBM-compatible computer systems.
1.5.11  ASCII code
The ASCII code is pronounced as ASKEE and is used for the same purpose for which the EBCDIC code is used. However, this
code is more popular than EBCDIC code as unlike the EBCDIC code this code can be implemented by most of the non-IBM
computer systems. Initially, this code was developed as a 7-bit BCD code to handle 128 characters but later it was modified to an
8-bit code.
1.5.12  Gray Code
Gray code is another important code that is also used to convert the decimal number into 8-bit binary sequence. However, this
conversion is carried in a manner that the contiguous digits of the decimal number differ from each other by one bit only.
Decimal Number 8-Bit Gray Code
0 00000000
1 00000001
2 00000011
3 00000010
4 00000110
5 00000111
6 00001111
7 00001011
8 00001001
9 00001101
We can convert the Gray coded number to its binary equivalent by remembering the following two major rules:
•	 The Most Significant Bit (MSB) of the Gray coded number and the equivalent binary number is always the same.
•	 The next-to-most significant bit of the binary number can be determined by adding the MSB of the binary number
to the next-to-most significant bit of the gray coded number.
Introduction to computer
9
1.5.12  1! and 2 ! Complement
Fixed point representation and floating point representation
+ve numbers are stored in register of digital computer in sign magnitude form
Negative numbers are stored in three different way
a.	 Signed magnitude representation
b.	 Signed 1s complement representation
c.	 Signed 2s complement representation
Why do we require 1! and 2! Complement?
One’s complement and two’s complement are two important binary concepts. Two’s complement is especially important because it
allows us to represent signed numbers in binary, and one’s complement is the interim step to finding the two’s complement.Two’s
complement also provides an easier way to subtract numbers.
Example
(9)10
to binary is (0 0001001)2
Note: here MSB 0 indicate + sign
(-9)10
to binary is
a.	 1 0001001 signed magnitude
b.	 1 1110110 signed 1s complement
c.	 1 1110111 signed 2s complement
Note: 2s complement can be formed by leaving LSB unchanged and remaining taking 1s complement
1.5.13  Rules for binary addition and subtraction
a. Addition b. Subtraction
0 + 0 = 0 0 - 0 = 0
0 + 1 = 1 0 - 1 = 1 borrow 1
1 + 0 = 1 1 - 0 = 1
1 + 1 = 1 carry 0 1 - 1 = 0
Example
1. Addition 2. Subtraction
1 0 1 1 0 1 (Augend) 1 0 1 1 0 1 (Minuend)
1 0 0 1 1 1 (Addend) 1 0 0 1 1 1 (Subtracted)
1 1 1 1
1 0 1 0 1 0 0 0 0 0 1 1 0
Sum = 1010100 Difference=1010100
1.5.14  Binary Multiplication
The multiplication of two binary numbers can be carried out in the same manner as the decimal multiplication. Unlike decimal
multiplication, only two values are generated as the outcome of multiplying the multiplication bit by 0 or 1 in the binary
multiplication. These values are either 0 or 1.
Computer Concepts and Fundamentals of Programming
10
The binary multiplication can also be considered as repeated binary addition. Therefore, the binary multiplication is performed in
conjunction with the binary addition operation.
A B A×B
0 0 0
0 1 0
1 0 0
1 1 1
				
1 1 0 0
1 0 1 0
0 0 0 0
1 1 0 0
0 0 0 0
1 1 0 0
1 1 1 1 0 0 0 	
1.5.15  Binary Division
Binary division is also performed in the same way as we perform decimal division. Like decimal division, we also need to follow
the binary subtraction rules while performing the binary division. The dividend involved in binary division should be greater than
the divisor. The following are the two important points, which need to be remembered while performing the binary division. If
the remainder obtained by the division process is greater than or equal to the divisor, put 1 in the quotient and perform the binary
subtraction. If the remainder obtained by the division process is less than the divisor, put 0 in the quotient and append the next
most significant digit from the dividend to the remainder.
Example Perform the binary division of the decimal numbers 18 and 8.
The equivalent binary representation of the decimal number 18 is 10010.
The equivalent binary representation of the decimal number 8 is 1000.
1.2.16  Floating point representation
1 0 0 0 ) 1 0 0 1 0 ( 1 0 → Quotient
1 0 0 0
0 0 0 1 0
0 0 0 0 0
0 0 0 1 0 → Remainder
Floating-point numbers are the numbers containing two different parts, integer part and fractional part. The floating-point
numbers are also referred as real numbers. A notation known as scientific notation is used to represent the real numbers in the
computer system. The scientific notation, also called exponential notation, represents the real numbers in the following form:
325.123 → 3.25123 × 102
0.000000245 → 2.45 × 10-7
1000.0101 → 1.0000101 × 23
4333.123
4.333123 × 103
43.33123 × 102
433.3123 × 101
CHAPTER – 2
COMPUTER SOFTWARE
2.1  Computer software
Computer software is software programs, applications, scripts, code written in any computer language which can be executed
and instruction. In order to access hardware directly it requires software. In other word various kinds of programs used to operate
computers and related devices can be also termed as software.
2.2  Types of software
	 i.	 System software
	 a.	 Operating system
			Operating system is an interface between the hardware and the user.
	 b.	 System utility
	 ii.	 Application software
	 a.	 Word processing
	 b.	 Spread sheets
	 c.	Database
	 d.	 Web browser
2.3  Compter networking
2.3.1  Types of computer networks
i.	 LAN
•	 This is a local area network up to 100 meters with speed of 100 Mbps to 1000 Mbps
•	 Any computer network for business, school, and college is termed as local area network.
•	 LAN can bet connected to other LAN by means of bridges
•	 Multiple LAN connected forms a WAN
•	 On LAN users can share expensive devices, such as laser printers, as well as data. 
•	 It works much faster as compared to traditional telephone network
•	 Topology, Protocol and media distinguishes one LAN from another
•	 Number of devices are connected by means of switch, or stack of switches, using a private addressing scheme.
•	 The media generally used for LAN is twisted pair cables or coaxial cables
•	 Less congestion in the network
Computer Concepts and Fundamentals of Programming
12
ii.	 MAN
•	 This A metropolitan area network. It is larger than LAN or group of LAN
•	 A network up to a city, big university, telephone company network is termed as MAN
•	 It interconnect several local area networks by bridging them with backbone lines
•	 Less fault tolerance and more congestion in the network
•	 It is costlier than Lan for implementation
•	 Devices used are Modem ,Wire/Cable, repeaters
•	 It’s hard to design and maintain a Metropolitan Area Network.
•	 Data transfer rate and the propagation delay is moderate
iii.	 WAN
•	 This a wide area network
•	 Data speed is lower 1/10 th of LAN
•	 Propagation delay is one of the biggest problems
•	 It has two types asynchronous transfer mode (ATM) network and Point-to-Point WAN
•	 Devices used in WAN are Optic wires, Microwaves and Satellites. 
•	 Communication medium used is PSTN or Satellite Link.
•	 More noise and error in data transmission
There are other types of networks other than this are as follows
i.	 PAN (Personal Area Network)
ii.	 SAN (Storage Area Network)
iii.	 EPN (Enterprise Private Network)
iv.	 VPN (Virtual Private Network)
2.3.2 Topology
Method of arranging and connecting different computer on the network with different way is termed as topology. There are
different topologies as follows:
Fig: 5.1
Computer software
13
i.	 BUS topology
•	 All computers are connected by means of single backbone cable
•	 Terminators are used to avoid the bouncing of the signals
•	 There is no dedicated client server architecture existing in this topology
•	 All computers are connected by means of T connectors to the backbone cable
•	 Failure of backbone cable bring down the complete network
ii.	 STAR topology
•	 All computers are connected in star fashion by means of switch
•	 Message is being broadcasted
•	 Wastage of bandwidth
•	 Failure of centralize switch bring down the complete network
•	 Switch/hub can act as repeater or signal booster.
•	 Unshielded Twisted Pair (UTP) Ethernet cable is used to connect computers.
•	 Failure of one node does not affect the network
•	 Performance such topology is depended on capacity of central device
iii.	 RING topology
•	 All the devices are connected to each other in the shape of a ring or a loop.
•	 It connects all nodes and forms a closed loop.
•	 Here new term token is used
•	 Computer wants to pass a message, then it catches the token, attaches a message, and then transmits around the
network. When its transmission is complete, the device passes the token to the next.
•	 It much secure way of communication
•	 Moving, adding and changing devices may affect the network
•	 No need for network server to control the connectivity
•	 A dual ring topology can be used as a backup if the first ring fails.
•	 Slower than a star topology.
iv.	 MESH topology
•	 It has two types full mesh and partial mesh topology
•	 In full mesh topology every node is connected with rest of the node
•	 It is very expensive topology.it will need a lot of capital to invest
•	 A broken node won’t distract the transmission of data in a mesh network.
•	 It has huge bandwidth
•	 It makes large data center
•	 Maintaining mesh networks can be very hard to manage.
•	 Network redundancy problem
v.	 TREE topology
•	 Its combination of BUS and Star topology
•	 It is highly scalable topology
•	 Identifying the faulty is easy
•	 Best for implementation of temporary networks.
Computer Concepts and Fundamentals of Programming
14
•	 Point to point connection for every devices
•	 If one device is damaged it doesn’t affect the network
•	 Failure of backbone cable bring down the complete network
•	 This network is insecure, anybody can see transmitted data.
•	 As more and more nodes maintenance becomes difficult
vi.	 CELLULAR topology
•	 This topology is mainly used for mobile communication.
•	 It forms cellular structure and any authentic mobile device comes in vicinity of the network gets connected with
the network.
•	 Every cell represents cell represents a portion of the total network area.
•	 In this topology every node transmits in a certain area called a cell.
•	 Data transmission is in the form of cellular digital packet data.
2.3.3  Computer network devices
i.	 HUB
•	 Hub is generally used in LAN.
•	 There are two types of hub active (with external power supply) and passive(without external power supply).
•	 It handles a data types like frames then transmits to the destination port
•	 Hub broadcasts the data
•	 Hubs are stupid devices as they cannot distinguish between data ,which port a frame should be sent to
•	 Passive hub don’t amplify the signals
•	 Hubs works in data link layer of OSI reference model.
ii.	 Switch
•	 Switches is generally used in LAN.
•	 Switches works in data link layer of OSI reference model.
•	 It handles a data types like frames then transmits to the destination port
•	 It filters the packets and regenerating forwarded packets.
•	 It reduces the collision rate.
•	 Many switches are self-learning.
•	 Switches may have different port with different speed of transmission.
•	 Almost one-half of the nodes connected to a switch can send data at the simultaneously.
iii.	 Router
•	 It works in the network layer of OSI reference model
•	 It filter out network traffic
•	 It dividing networks logically instead of physically.
•	 Ip router divides network into many segments
•	 It routs the packet to the particular network
•	 There are two types of router static and dynamic
•	 For every packet it calculate checksum, and rewrite the MAC header
Computer software
15
iv.	 Bridge
•	 It connects two or more LAN networks
•	 It works in data link layer of OSI reference model
•	 It segment’s the larger network
•	 It has the capacity to block the incoming flow of data.
•	 It can build a list of the MAC addresses
•	 The types of bridges are Transparent Bridge, Source Route Bridge, Translational Bridge
v.	 Gateway
•	 It is a stopping point for data from other networks
•	 This is a specialized computer.It also operates as a firewall and a proxy server.
•	 It controls all of the data traffic your Internet Service Provider (ISP)
•	 It keeps out unwanted traffic to get in private network.
•	 Network interface cards (NIC/LAN card)
•	 This is also called as LAN card, Ethernet card ,interface controller card, expansion card, network card, network
adapter or network adapter card (NAC)
•	 This is working in the physical layer of OSI reference model
•	 It has RJ45 port through which it gets connected to network
2.3.4  OSI reference model
Fig: OSI reference model
Computer Concepts and Fundamentals of Programming
16
2.3.5 TCP/IP
TCP/IP is normally considered to be a 4 layer system. The 4 layers are as follows:
i.	 Application layer
ii.	 Transport layer
iii.	 Network layer
iv.	 Data link layer
Application layer
This layer includes applications or processes that use transport layer protocols to deliver the data to destination computers. The
list of application layer protocols are:
i.	 HTTP (Hypertext transfer protocol)
ii.	 FTP (File transfer protocol)
iii.	 SMTP (Simple mail transfer protocol)
iv.	 SNMP (Simple network management protocol) etc.
Transport layer:
This is a backbone to data flow between two hosts. This layer receives data from the application layer above it. There are many
protocols that work at this layer but the two most commonly used protocols at transport layer are TCP and UDP.
Network layer:
The main purpose of this layer is to organize or handle the movement of data on network. The main protocol used at this layer is
IP. While ICMP (used by popular ‘ping’ command) and IGMP are also used at this layer.
Data link layer:
This layer mainly consists of device drivers in the OS and the network interface card attached to the system. Both the device
drivers and the network interface card take care of the communication details with the media being used to transfer the data over
the network.
Fig: TCP/IP layered model
2.3.6 Firewall
A firewall is a protective barrier between your PC and internet. When you are connected to the Internet, you are a potential target
to of cyber threats, such as hackers that attack through security loopholes.
Types of firewall are as follows
Hardware: A hardware firewall can be a router or any other security product that is placed between your PC and the outside world.
More than one PC can be connected with that security device or router, and each will be protected by the firewall.
Computer software
17
Software: A software firewall is installed on your PC, it will deflect incoming attacks and hide open ports. It will warn you about
suspicious outgoing traffic. You can have a software firewall on each computer for strong protection. By installing software firewall,
an attacker will have to cross two level security to access your PC.
Fig: Firewall
2.3.7  IP and classes of IP(IPV4)
This 32 bit address mechanism for addressing the devices on the network. Different classes of IP address as per the IPV4 standard
are as follows:
v.	 Class A –(0-126)
vi.	 Class B-(128-191)
vii.	 Class C-(192-223)
viii.	 Class D-(224-239)
ix.	 Class E-(240-255)
The 127 is used by the local host as loop back adapter and for the inter processes communication. In the above list class D and E
are used for the experimental purpose.
CHAPTER – 3
INTRODUCTION
3.1  Origin of C language
‘C’ is a multi-purpose language (including system programming) whose development is linked to UNIX operating system. Many
of the features of ‘C’ language stem from BCPL (developed by Martin Richards) and B (developed by Ken Thompson). Both
BCPL and B are “type less” languages while C provides a variety of data types.
It may not be an exaggeration to say that 'C' programming language, developed by Dennis Ritchie, circa 1969-1973 (although
quite a few book quote the year as 1972), is one of the most powerful, general-purpose programming languages which has also
inspired many other languages. In 1978, Dennis Ritchie and Brian W. Kernighan published the seminal book The C Programming
Language (the version of the language described in the book is known as KR C) which served as a language definition and a
formal reference that helped in vast popularization of the 'C' language. In 1983, ANSI instituted the X3J11 committee which
was assigned a goal of developing a 'C' standard. The X3J11 committee produced its report by the end of 1989 – ANSI X3.159-
1989 “Programming Language C”. This version of 'C' is known as C89. This standard was ratified by ISO as ISO/IEC 9899-1990
(sometimes referred to as C90). In fact, C89 and C90 refer to the same language.
In 1995, ISO released an extension to the internationalization support to the standard. This version is known as C95. A revised
standard was again released in 1999 (now known as C99). In 2007, work began on yet another revision of the C standard resulting
in the development of the C11 standard which was approved in December 2011.
C89 contains 32 keywords which are given below:
auto break case char
const continue default do
double else enum extern
float for goto if
int long register return
short signed sizeof static
struct switch typedef union
unsigned void volatile while
C99 has 37 keywords. The five new keywords which were added are:
_Bool, _Complex, _Imaginary, inline, restrict
C11 has 44 keywords. The seven new keywords which have been added are:
_Alignas, _Alignof, _Atomic, _Generic, _Noreturn, _Thread_local, _Static_assert
Interestingly, 'C' language used to include a reserved keyword called entry, which in fact was never implemented and now has
been removed as a reserved word.
Introduction
19
3.2  Why C?
3.3  Structure of C program
3.3.1  Performing addition of two numbers with following constraint
a) do not use –(-) operation
b) do not use *(-1) operation
c) do not use (a2-b2)/a-b operation
#includestdio.h
main()
{
int add ,diff, a,b;
printf(nEnter the value of two numbersn );
scanf(%d%d,a,b);
add = 2*a;
diff = a - b;
add=add-diff;
printf(nThe addition of 2 nos without using + is:==%d ,add);
}
3.3.2  The first function to be executed in a ‘C’ program:
All 'C' programmers know that the main() function is the entry point for a 'C' program. Can a user-defined function be executed
before the main() function in a 'C' program? Can a user-defined function be executed after the last statement in main() function
in a 'C' program? Can the main() function be called explicitly from within another function? Can the return value from the
main() function be utilised in a program? These questions often pose a serious challenge to a 'C' programmer. The program below
(compiled using gcc) answers the aforementioned questions:
/*The code below is explained in greater detail in Chapter 2*/
#includestdio.h
void func1(void) __attribute__((constructor));
void func2(void) __attribute__((destructor));
main()
{
printf(nWithin main());
return -8;
}
void func1()
{
system(clear);
printf(nWithin func1());
}
Computer Concepts and Fundamentals of Programming
20
void func2()
{
int k = main();
printf(nWithin func2(), k = %d, k);
}
A sample output of the program is given below:
Within func1()
Within main()
Within main()
Within func2(), k = -8
The output of the above code testifies that func1() is called first, after which main() function is executed, after which func2()
function is called, which in turn explicitly calls main() function which in turn returns -8 which is stored in integer variable k.
[N.B. Two underscores precede the word attribute and two underscores follows the word attribute in the statements: void
func1(void) __attribute__((constructor)); and void func2(void) __attribute__((destructor));]
For those working on the TurboC compiler, the following program can be used:
#includestdio.h
void func1();
void func2();
#pragma startup func1
#pragma exit func2
main()
{
printf(nWithin main());
return -8;
}
void func1()
{
system(clear);
printf(nWithin func1());
}
void func2()
{
int k = main();
printf(nWithin func2(), k = %d, k);
}
Introduction
21
3.4.2  Executing a ‘C’ program using gcc
Open an editor like gedit, kwrite
Type the c program and save it with the
extension .c
if no error(s) then type the command: ./a.out
Open terminal and type command gcc
filename.c
Compiling a 'C' program using gcc: exploring a few switches
The gnu C compiler is widely used because of its versatility (it can carry out preprocessing, compilation, assembly and linking) and
also it has set unmatched standards in terms of reliability. The gnu C compiler actually works in stages. The stages are as follows:
the Source Code is converted into Translation Unit
the Translation Unit is converted into Assembly Code
the Assembly Code is converted into Object Code
the Object Code is converted into an Executable File.
As an instance, if a program is saved by the name test57.c, then on issuing the command:
gcc test57.c
the intermediate stages might be visualized as follows:
test57.c → test57.i → test57.s → test57.o → a.out
The following switches can be used with the gcc command line in order to examine the intermediate stages:
gcc –E test57.c (in order to obtain the Translation Unit equivalent. In short the –E option tells gcc to stop compilation after
preprocessing)
gcc –S test57.c (in order to obtain the Assembly Code)
gcc –c test57.c (in order to obtain the Object Code).
gcc test57.c (in order to obtain the executable file a.out)
[NOTE: The options –E and –S are in uppercase]
Let us consider the code snippet (saved in a file test57.c, for instance) shown below:
#includestdio.h
main()
{
printf(Computer Science);
return 0;
}
Computer Concepts and Fundamentals of Programming
22
In order to examine the intermediate assembly language file, the following commands can be used.
$ gcc -S test57.c
$ cat test57.s
will produce the intermediate assembly language listing of the above code snippet.
The command
$ gcc -o test test57.c
makes an executable file by the name of test. In order to look at the output now, the user can type the following command at the
command line:
$./test
instead of typing./a.out.
The GNU Compiler Collection (gcc) can compile programs written in several high level languages such as FORTRAN, C, C++,
Java, Objective-C, etc. In order to determine languages whose programs can be compiled using gcc, the Package Manager rpm*
can be used as illustrated below:
$ rpm -qa | grep gcc
A sample interaction with rpm (using it as suggested above) might appear as follows:
compat-gcc-34-g77-3.4.6-4
gcc-4.1.2-14.el5
gcc-gfortran-4.1.1-52.el5
compat-gcc-34-c++-3.4.6-4
gcc-java-4.1.1-52.el5
compat-gcc-34-3.4.6-4
gcc-c++-4.1.1-52.el5
compat-libgcc-296-2.96-138
libgcc-4.1.2-14.el5
gcc-objc-4.1.1-52.el5
*rpm is a package manager which can be used to build, install, update, query and erase individual software packages.
[N.B. gcc used to be the GNU 'C' Compiler, but is now used for GNU Compiler Collection.]
In order to compile the program, the following instruction needs to be typed:
gcc program-name.c -trigraphs
To find out the version of gcc, one can use
gcc -v
The gdb utility in Linux
gdb (GNU debugger) is an efficient utility for debugging a program that has been compiled by gcc (GNU compiler collection).
In order to start gdb the user is only required to type gdb and press ENTER at the command line (although there are many
alternatives of starting gdb).
Let us understand using gdb through a sample program (Program listing one)
Program listing one
Introduction
23
#includestdio.h
main()
{
	 double num1, num2, quot;
	 printf(Enter the numerator: );
	 scanf(%lf, num1);
	 printf(Enter the denominator: );
	 scanf(%lf, num2);
	quot=num1/num2;
	 printf(n%lf/%lf=%lf, num1, num2, quot);
return 0;
}
Suppose the above program is stored in a file by the name of test.c. In order to compile the program, the user may type:
$ gcc -g test.c -o test
It may not be meaningful to use gdb by compiling the program without the -g switch, since gdb will not have information related
to variable names, function names, line numbers, etc. Once the program is compiled, the user can type
$ gdb test
Now, in order to run the program, the user can type run (or r) at the gdb prompt and press ENTER.
[NOTE: The user can also type gdb -quiet test or gdb -q test in order to suppress the introductory and copyright messages which
are displayed when gdb is invoked.]
In order to list the program, the user can type list (or l) at the gdb prompt and press ENTER.
In order to set a breakpoint at line number 10, the user can type b 10 at the gdb prompt and press ENTER. Function name
can also be used for setting a breakpoint at the first executable statement within the function. After pausing at the indicated line,
the user can type continue (or c) in order to continue executing the program. The breakpoint(s) can be deleted through the delete
command.
Once a breakpoint has been set, then the commands n (for next) and s (for step) can also be used to execute the next line of the
program. The commands n and s work differently if the next line happens to be a function call. If n is used then the next pause
will be at the statement following the function call, whereas, if s is used then the next pause will be at the first line of the function
which is invoked.
The bt command can be used for printing the current location within the program and the stack trace showing how the current
location was reached if a function calls another function or itself i.e. there has been a series of function calls. The kill command can
be used in order to terminate the program being executed in gdb. The help command can be typed at the gdb prompt if the user
feels stuck anywhere. If the user wants to quit the gdb utility then the user should type q and press ENTER.
CHAPTER – 4
DATA TYPES AND OPERATORS
4.1  Data Types
Data (singular: datum, plural: data) are a collections of facts and figures. Data will be of particular type. For instance, 786 is an
integer, 0.23 is a fractional value and ‘x’ is a letter of the English alphabet.
The built-in data types in ‘C’ are as follows:
Type Example Format specifier
char char c = ‘a’; %c
int int num = 786; %d, %i
float float f = 0.3f %f, %e, %E, %g, %G
double double d = 0.9876 %lf
void Used with functions and pointers. It is wrong to write void a.
Format specifiers are also known as conversion characters/format code.
In ‘C’, a string is an array of characters terminated by the NULL character ‘0’ – backslash zero. The format specifier for string is %s.
Use of Format specifiers %o and %x
Data types and operators
25
Sample Program 4.1
/* for printing octal and hexadecimal equivalents of an integer */
#includestdio.h
main()
{
int num = 9123;
printf(nIn base 10, num = %d, num);
printf(nIn base 8, num = %o, num);
printf(nIn base 16, num = %x, num);
return 0;
}
A sample output is shown below:
In base 10, num = 9123
In base 8, num = 21643
In base 16, num = 23a3
Sample Program 4.2
/*When 0 (zero) and 0x precede an integer*/
#includestdio.h
main()
{
int num1 = 03672; /* when an integer begins with 0, then it implies that it is an octal integer*/
int num2 = 0x3672; /* when an integer begins with 0x, then it implies that it is an hexadecimal integer*/
int num3 = 3672;
printf(nnum1 = %d, num1);
printf(nnum2 = %d, num2);
printf(nnum3 = %d, num3);
return 0;
}
A sample output is shown below:
num1 = 1978
num2 = 13938
num3 = 3672
In C99, _Bool is also a data type. _Bool is a datatype for Boolean (true/false). The stdbool.h header files defines an alias bool for _Bool.
Arrays, structures, enumerations are derived data types in ‘C’.
‘C’ language supports user-defined datatypes also.
A variable declaration statement such as
int n = 953;
means four bytes will be given the name n and the integer 953 will be stored in these four bytes.
Computer Concepts and Fundamentals of Programming
26
Escape sequences in ‘C’
An escape sequence in ‘C’ usually begins with the backslash () and is a sequence of two or more characters which when used inside
a character or string literal is translated into another character or sequence of characters.
Escape sequence Character represented
a alarm i.e. a beep sound or a bell sound
b backspace
f formfeed
n linefeed i.e. new line
r carriage return
t horizontal tab
v vertical tab
 backslash
’ single quotation mark
” double quotation mark
? question mark
printf(): A function for displaying output; scanf(): A function for accepting input.
Obtaining an integer as input from the user:
Sample Program 4.3
#includestdio.h
main()
{
int num;
printf(Enter an integer: );
scanf(%d, num);
printf(nThe integer you entered is: %d, num);
return 0;
}
Data types and operators
27
A sample output is shown below:
Enter an integer: 786
The integer you entered is: 786
Sample Program 4.4
Obtaining a fractional number as input from the user:
#includestdio.h
main()
{
float num;
printf(Enter a fractional value: );
scanf(%f, num);
printf(nThe fractional value you entered is: %f, num);
return 0;
}
A sample output is shown below:
Enter a fractional value: 0.34
The fractional value you entered is: 0.340000
The sizeof() operator [sizeof() is an unary operator] in C can be used to determine the size (in bytes) of a variable, constant or datatype.
Sample Program 4.5
#includestdio.h
main()
{
printf(nsizeof(0.93) = %d, sizeof(0.93));
printf(nsizeof(0.93f) = %d, sizeof(0.93f));
printf(nsizeof(71) = %d, sizeof(71));
printf(nsizeof(71L) = %d, sizeof(71L)); /*lowercase L can also be used*/
return 0;
}
Obtaining a string as input from the user:
Sample Program 4.6
#includestdio.h
main()
{
char name[80];
printf(Enter your name: );
scanf(%s, name);
printf(nThe name you entered is: %s, name);
return 0;
}
Computer Concepts and Fundamentals of Programming
28
Enter your name: Ganesh Ingle
The name you entered is: Ganesh
When reading a string through scanf(%s, name);
The scanf() stops reading after the first whitespace (tab, space or Enter). Therefore Ingle was not stored in name. In order to read
blank spaces into a string variable, the scanf() function can be used as illustrated below:
Sample Program 4.7
#includestdio.h
main()
{
char name[81];
printf(nEnter your name: );
scanf(%[^n]s, name); /* whatever you type before pressing the ENTER key will be stored in name*/
printf(nYou entered: %s, name);
return 0;
}
Enter your name:Ganesh Ingle
You entered: Ganesh Ingle
Sample program 4.8
/* Program illustrating the use of sizeof() operator */
#includestdio.h
main()
{
printf(nsizeof(char) = %d, sizeof(char));
printf(nsizeof(int) = %d, sizeof(int));
printf(nsizeof(float) = %d, sizeof(float));
printf(nsizeof(double) = %d, sizeof(double));
printf(nsizeof(long int) = %d, sizeof(long int));
return 0;
}
sizeof(char) = 1
sizeof(int) = 4
sizeof(float) = 4
sizeof(double) = 8
sizeof(long int) = 4
sample program 4.9: The program below exemplifies the use of long long in 'C' langauage.
Program listing
#includestdio.h
main()
{
long long n=1; /* The range of long long is from –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 */
int i;
Data types and operators
29
system(clear);
for(i=1;i11;i++)
{
printf(n%lld,n*n);
n=n*10+1;
}
return 0;
}
Sample program 4.10. To print the message I am the one without using any semicolon through out the program
#includestdio.h
main()
{
if(printf(I am the one))
{
}
}
4.11 The program to print message without using {,} in the program using di graph.
#includestdio.h
main()
%
printf(nhello welcome to TMIn);
printf(nGMn);
printf(nnCompletedn);
%
Sample program 4.12The program to print message without using {,} in the program using tri-graph characters.
#includestdio.h
main()
??
printf(nhello welcome to TMIn);
printf(nGMn);
printf(nnCompletedn);
??
4.2  Data models
The choices made by each implementation about the sizes of the fundamental types are collectively known as data model. Four
data models found wide acceptance:
32 bit systems:
•	 LP32 or 2/4/4 (int is 16-bit, long and pointer are 32-bit)
•	 Win16 API
Computer Concepts and Fundamentals of Programming
30
•	 ILP32 or 4/4/4 (int, long, and pointer are 32-bit);
•	 Win32 API
•	 Unix and Unix-like systems (Linux, Mac OS X)
64 bit systems:
•	 LLP64 or 4/4/8 (int and long are 32-bit, pointer is 64-bit)
•	 Win64 API
•	 LP64 or 4/8/8 (int is 32-bit, long and pointer are 64-bit)
•	 Unix and Unix-like systems (Linux, Mac OS X)
Other models are very rare. For example, ILP64 (8/8/8: int, long, and pointer are 64-bit) only appeared in some early 64-bit Unix
systems (e.g. Unicos on Cray).
4.3 Constants
Constants are of two types
	 a.	 Numeric Constants
•	 Integer Constants (eg. 1,-15, 045, 0X6)
•	 Real Constants (eg.3.14)
	 b.	 Character Constants
•	 Single Character Constants(eg. ‘5’ ,’z’)
•	 String Constants (eg. “IMU”
•	 Backslash Character Constants
Eg:
Constants Meaning
a beep sound
b backspace
f form feed
n new line
r carriage return
t horizontal tab
v vertical tab
' single quote
 double quote
 backslash
0 null
Data types and operators
31
4.4 Operators
4.4.1  Arithmetic Operators
Operator Description Example
+ Adds two operands. A + B = 30
− Subtracts second operand from the first. A − B = -10
* Multiplies both operands. A * B = 200
/ Divides numerator by de-numerator. B / A = 2
% Modulus Operator and remainder of after an integer division. B % A = 0
++ Increment operator increases the integer value by one. A++ = 11
-- Decrement operator decreases the integer value by one. A-- = 9
4.4.2  Relational Operators
Operator Description Example
== Checks if the values of two operands are equal or not. If yes, then the condition becomes true. (A == B) is not true.
!= Checks if the values of two operands are equal or not. If the values are not equal, then the condition becomes true. (A != B) is true.
 Checks if the value of left operand is greater than the value of right operand. If yes, then the condition becomes true. (A  B) is not true.
 Checks if the value of left operand is less than the value of right operand. If yes, then the condition becomes true. (A  B) is true.
= Checks if the value of left operand is greater than or equal to the value of right operand. If yes, then the
condition becomes true.
(A = B) is not true.
= Checks if the value of left operand is less than or equal to the value of right operand. If yes, then the condition
becomes true.
(A = B) is true.
4.4.3  Logical Operators
Operator Description Example
 Called Logical AND operator. If both the operands are non-zero, then the condition becomes true. (A  B) is false.
|| Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true. (A || B) is true.
! Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is true, then
Logical NOT operator will make it false.
!(A  B) is true.
Sample Program 4.13
/*illustration of postfix and prefix */
#includestdio.h
main()
{
int num1 = 7;
int num2, num3;
num2 = num1++; /*first assign the value of num1 (7 in this case) to num2 and thereafter increment the value of num1*/
printf(nnum1 = %d, num1);
printf(nnum2 = %d, num2);
num3 = ++num1; /*first increment the value of num1, and then assign the value of num1 to num3*/
printf(nnum1 = %d, num1);
Computer Concepts and Fundamentals of Programming
32
printf(nnum3 = %d, num3);
return 0;
}
A sample output is shown below:
num1 = 8
num2 = 7
num1 = 9
num3 = 9
Sample program 4.14
/* to find the angle between the hour hand and the minute hand*/
#includemath.h
#includestdio.h
main()
{
int h, m;
double a1, a2;
system(clear);
printf(nthis code determines the angle between the hour hand and the minute hand);
printf(Enter time (h m): );
scanf(%d %d, h, m);
a1 = fabs(((h * 30) + (m * 1/2.0)) - (m * 6));
a2 = 360 - a1;
printf(nTime = %d:%d, h,m);
printf(nAngle between the hour hand and minute hand: %lf %lf, a1,a2);
printf(nnCompletedn);
return 0;
}
4.4.4  Ternary operator
Conditional operators return one value if condition is true and returns another value is condition is false.This operator is also called
as ternary operator.
Syntax:	 (Condition? true_value: false_value);
Example:	(A  100? 0: 1);
4.4.5  Bitwise Operator
p q p  q p | q p ^ q
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1
Data types and operators
33
Operator Description Example
 Binary AND Operator copies a bit to the result if it exists in both operands. (A  B) = 12, i.e., 0000 1100
| Binary OR Operator copies a bit if it exists in either operand. (A | B) = 61, i.e., 0011 1101
^ Binary XOR Operator copies the bit if it is set in one operand but not both. (A ^ B) = 49, i.e., 0011 0001
~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. (~A ) = -61, i.e,. 1100 0011
in 2's complement form.
 Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the
right operand.
A  2 = 240 i.e., 1111 0000
 Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by
the right operand.
A  2 = 15 i.e., 0000 1111
4.4.6  Assignment operator
Operator Description Example
 Binary AND Operator copies a bit to the result if it exists in both operands. (A  B) = 12, i.e., 0000 1100
| Binary OR Operator copies a bit if it exists in either operand. (A | B) = 61, i.e., 0011 1101
^ Binary XOR Operator copies the bit if it is set in one operand but not both. (A ^ B) = 49, i.e., 0011 0001
~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. (~A ) = -61, i.e,. 1100 0011 in
2's complement form.
 Binary Left Shift Operator. The left operands value is moved left by the number of bits specified
by the right operand.
A  2 = 240 i.e., 1111 0000
 Binary Right Shift Operator. The left operands value is moved right by the number of bits specified
by the right operand.
A  2 = 15 i.e., 0000 1111
4.4.7  Programs for practice
Write a C program to solve following problems
1.	 To find the square of the number given by user.
2.	 To perform addition of two numbers entered by user.
3.	 To perform addition of two numbers without using + operator.
4.	 To calculate average of three real numbers entered by user.
5.	 To input a single character and display it with proper message.
6.	 To show the effect of various escape sequences.
7.	 To swap the values of two variables without using third variable.
8.	 To input the rainfall of three consecutive days in cms and find its a average. Print the output with proper messages.
9.	 Find the simple interest. Inputs are principal amount, period in year and rate of interest.
10.	 To enter a integer number and carry out modular division operation by 2,3 and 6 and display the result.
11.	 To find the average temperature of five sunny days. Assume the temperature in Celsius.
12.	 Find the area and perimeter of a) Square b) Rectangle c) triangle Accept the sides as input from user.
13.	 The speed of a van is 75 km/hr. Write a program to find the number of hours required for covering a distance of 500 km.
14.	 Write a program to evaluate the following expressions and display their results.
15.	 x2 + 2x3*(2*x)
16.	 (x+y+z)2
17.	 Write a program to read three integers from the keyboard using one scanf statement and output them on one line using:
18.	 Three printf statements,
19.	 Only one printf with conversion specifiers.
Computer Concepts and Fundamentals of Programming
34
20.	 Calculate the volume and area of a sphere using the formulas:
21.	 V = 4µr3/3
22.	 A = 4µr2
23.	 test the program using the values for the radius.
24.	 WAP to Calculate the mass of air in an automobile tire, using the formula PV = 0.37m(T + 460)where P = pressure in
pounds per square inch, V= volume in cubic feet, m=mass of air in pounds, T=temp. In Fahrenheit. The tire contains two
cubic feet of air. Assume that the pressure is 32psi at room temperature.
CHAPTER – 5
DECISION CONTROL INSTRUCTIONS
The decision control instructions are broadly classified as:
1.	 if statement
2.	 if else statement
3.	 switch case statement
5.1  if statement
if (test condition)
{
Statement 1;
Statement 2;
Statement 3;
………….
………….
Statement n;
}
5.2  if else statement
if (test condition)
{
Statement 1;
Statement 2;
………….
………….
Statement n;
}
else
{
Statement 1;
Statement 2;
………….
………….
Statement n;
}
Computer Concepts and Fundamentals of Programming
36
5.3  nested if else statement
if(condition)
{
//Nested if else inside the body of if
if(condition2)
{
//Statements inside the body of nested if
}
else
{
//Statements inside the body of nested else
}
}
else
{
//Statements inside the body of else
}
5.4  if elseif else statement
if (test condition)
{
Statement 1;
Statement 2;
………….
………….
Statement n;
}
else if
{
Statement 1;
Statement 2;
………….
………….
Statement n;
}
else
{
Statement 1;
Statement 2;
………….
………….
Statement n;
}
Decision control instructions
37
5.5  switch case statement
The syntax of switch case construct is as follows
Switch ( expression ) // this expression can int or char it should not be float or string
{
case value-1:
	block-1;
	break;
	 case value-2:
	block-2;
	break;
	 case value-3:
	block-3;
	break;
	 case value-4:
	block-4;
	break;
default:
	default-block;
	break;
}
5.6  goto statement
Generally goto is a unconditional jumping statement. It can be used as a loop statement as well. Beacusae of unconditional
jumping it is not advised to use goto statement.
Sample code that illustrates goto statement as follows
#includestdio.h
#includeconio.h
void main()
{
int number;
clrscr();
printf(“Mango”);
goto x; // here x is a label not a variable of any type ,program jumps to the label x abruptly.
y:
printf(“Orange”);
goto z; // here z is a label not a variable of any type ,program jumps to the label z abruptly.
x:
printf(“Banana”);
goto y; // here y is a label not a variable of any type ,program jumps to the label z abruptly.
z:
printf(“Apple”);
getch();
}
Computer Concepts and Fundamentals of Programming
38
Sample Program 5.1 Write a program to check whether the entered year is a leap year or not considering century year
condition (IMU question paper May June 2016)
#include stdio.h
#include conio.h
int main()
{
int year;
printf(Enter a year: );
scanf(%d,year);
if(year%4 == 0)
{
if( year%100 == 0)
{
// year is divisible by 400, hence the year is a leap year
if ( year%400 == 0)
printf(%d is a leap year., year);
else
printf(%d is not a leap year., year);
}
else
printf(%d is a leap year., year );
}
else
printf(%d is not a leap year., year);
getch();
return 0;
}
Or Other logic
#include stdio.h
#include conio.h
int main()
{
int year;
printf(Enter a year: );
scanf(%d,year);
if(year=1752)
{
if(year%4 == 0)
printf(%d is a leap year., year );
else
printf(%d is not a leap year., year );
}
else
{
Decision control instructions
39
if( year%100 == 0  year%400 != 0)
printf(%d is not a leap year., year);
else if( year%100 == 0  year%400 != 0)
printf(%d is a leap year., year);
else if(year%4 == 0)
printf(%d is a leap year., year );
else
printf(%d is not a leap year., year );
}
getch();
return 0;
}
Or other logic
/**
* C program to check Leap Year
*/
#include stdio.h
main()
{
int year;
/* Read year from user */
printf(Enter year: );
scanf(%d, year);
/*
* Check for leap year
*/
if(((year%4 == 0)  (year%100 !=0)) || (year%400==0))
{
printf(LEAP YEAR);
}
else
{
printf(COMMON YEAR);
}
}
Sample Program 5.2 Write program to device a calculator with menu driven program
# include stdio.h
# include conio.h
int main() {
char operator;
double firstNumber,secondNumber;
printf(Enter an operator (+, -, *, /): );
Computer Concepts and Fundamentals of Programming
40
scanf(%c, operator);
printf(Enter two operands: );
scanf(%lf %lf,firstNumber, secondNumber);
switch(operator)
{
case '+':
printf(%.1lf + %.1lf = %.1lf,firstNumber, secondNumber, firstNumber+secondNumber);
break;
case '-':
printf(%.1lf - %.1lf = %.1lf,firstNumber, secondNumber, firstNumber-secondNumber);
break;
case '*':
printf(%.1lf * %.1lf = %.1lf,firstNumber, secondNumber, firstNumber*secondNumber);
break;
case '/':
printf(%.1lf / %.1lf = %.1lf,firstNumber, secondNumber, firstNumber/firstNumber);
break;
// operator is doesn't match any case constant (+, -, *, /)
default:
printf(Error! operator is not correct);
}
getch();
return 0;
}
Sample program 5.3 Program to print three digit number in words
#includestdio.h
main()
{
int num, t, d1, d2, d3;
system(clear);
printf(This program is for printing a three digit integer in words: n);
printf(Enter an integer: );
scanf(%d, num);
if(num0)
{
t=-num;
printf(minus );
}
else if(num==0)
{ printf(zero);
t=num;
}
else
Decision control instructions
41
t=num;
d1=t/100;
d2=(t%100)/10;
d3=t%10;
if(d1==1)
printf(One hundred );
else if(d1==2)
printf(Two hundred );
else if(d1==3)
printf(Three hundred );
else if(d1==4)
printf(Four hundred );
else if(d1==5)
printf(Five hundred );
else if(d1==6)
printf(Six hundred );
else if(d1==7)
printf(Seven hundred );
else if(d1==8)
printf(Eight hundred );
else if(d1==9)
printf(Nine hundred );
if(d2==1)
{
if(d3==1)
printf(Eleven);
else if(d3==2)
printf(Twelve);
else if(d3==3)
printf(Thirteen);
else if(d3==4)
printf(Fourteen);
else if(d3==5)
printf(Fifteen);
else if(d3==6)
printf(Sixteen);
else if(d3==7)
printf(Seventeen);
else if(d3==8)
printf(Eighteen);
else if(d3==9)
printf(Nineteen);
}
else
{
if(d2==2)
printf(Twenty );
Computer Concepts and Fundamentals of Programming
42
else if(d2==3)
printf(Thirty );
else if(d2==4)
printf(Forty );
else if(d2==5)
printf(Fifty );
else if(d2==6)
printf(Sixty );
else if(d2==7)
printf(Seventy );
else if(d2==8)
printf(Eighty );
else if(d2==9)
printf(Ninty );
}
if(d2!=1)
{
if(d3==1)
printf(One);
else if(d3==2)
printf(Two);
else if(d3==3)
printf(Three);
else if(d3==4)
printf(Four);
else if(d3==5)
printf(Five);
else if(d3==6)
printf(Six);
else if(d3==7)
printf(Seven);
else if(d3==8)
printf(Eight);
else if(d3==9)
printf(Nine);
}
printf(nnCompletedn);
}
Sample program 5.4 Write a program to Find the roots of quadratic equation using switch case construct
/**
* C program to find all roots of a quadratic equation using switch case
*/
#include stdio.h
#include math.h //Used for sqrt()
main()
{
Decision control instructions
43
float a, b, c;
float root1, root2, imaginary;
float discriminant;
printf(Enter values of a, b, c of quadratic equation (aX^2 + bX + c): );
scanf(%f%f%f, a, b, c);
discriminant = (b*b) - (4*a*c);
/*
* Computes roots of quadratic equation based on the nature of discriminant
*/
switch(discriminant  0)
{
case 1:
//If discriminant is positive
root1 = (-b + sqrt(discriminant)) / (2*a);
root2 = (-b - sqrt(discriminant)) / (2*a);
printf(Two distinct and real roots exists: %.2f and %.2fn, root1, root2);
break;
case 0:
//If discriminant is not positive
switch(discriminant  0)
{
case 1:
//If discriminant is negative
root1 = root2 = -b / (2*a);
imaginary = sqrt(-discriminant) / (2*a);
printf(Two distinct complex roots exists: %.2f + i%.2f and %.2f - i%.2fn, root1, imaginary, root2, imaginary);
break;
case 0:
//If discriminant is zero
root1 = root2 = -b / (2*a);
printf(Two equal and real roots exists: %.2f and %.2fn, root1, root2);
break;
}
}
}
Sample program 5.5 Write a program to count minimum number of notes in an amount
/**
* C program to count minimum number of notes in an amount
*/
#include stdio.h
main()
{
int amount;
Computer Concepts and Fundamentals of Programming
44
int note500, note100, note50, note20, note10, note5, note2, note1;
note500 = note100 = note50 = note20 = note10 = note5 = note2 = note1 = 0 ;
/* Reads amount from user */
printf(Enter amount: );
scanf(%d, amount);
if(amount = 500)
{
note500 = amount/500;
amount -= note500 * 500;
}
if(amount = 100)
{
note100 = amount/100;
amount -= note100 * 100;
}
if(amount = 50)
{
note50 = amount/50;
amount -= note50 * 50;
}
if(amount = 20)
{
note20 = amount/20;
amount -= note20 * 20;
}
if(amount = 10)
{
note10 = amount/10;
amount -= note10 * 10;
}
if(amount = 5)
{
note5 = amount/5;
amount -= note5 * 5;
}
if(amount = 2)
{
note2 = amount /2;
amount -= note2 * 2;
}
if(amount = 1)
{
note1 = amount;
}
printf(Total number of notes = n);
printf(500 = %dn, note500);
printf(100 = %dn, note100);
printf(50 = %dn, note50);
Decision control instructions
45
printf(20 = %dn, note20);
printf(10 = %dn, note10);
printf(5 = %dn, note5);
printf(2 = %dn, note2);
printf(1 = %dn, note1);
}
Sample program 5.6 Write a program to check given number is even or odd using switch case
/**
* C program to check Even or Odd number using switch case
*/
#include stdio.h
main()
{
int num;
/*
* Reads a number from user
*/
printf(Enter any number to check even or odd: );
scanf(%d, num);
switch(num % 2)
{
//If n%2 == 0
case 0: printf(Number is Even);
break;
//Else if n%2 != 0
case 1: printf(Number is Odd);
break;
}
}
5.7  Programs for practice
1.	 WAP to find the roots of a quadratic equation by using if...else condition.
2.	 WAP to read six numbers and find the largest one by using ladder of if...else.
3.	 WAP to find the average of six subjects and display the results.
4.	 WAP to check whether the entered year is a leap year or not with all check points
5.	 WAP (a menu driven)to display the names of the days of a week.
6.	 WAP Read the values of a,b,c through keyboard. Add them and after addition check if it is in the range of 100  200 or not.
Print separate message of each.
7.	 WAP to convert integer to character using if condition.
8.	 WAP to calculate the sum of the remainders obtained by dividing with modular division operations by 2 on 1 to 9 numbers.
CHAPTER – 6
DECISION MAKING AND LOOPING
6.1  The for() loop
The for() loop can be used for executing a statement/statements a specific (or infinite) number of times.
The general form of the for() loop is as follows:
	 for(expr1; expr2; expr3)
	{
		code block;
	}
expr1 is executed only once when the for() loop is executed for the first time.
expr2 is evaluated every time before entry into the loop till the time it does not evaluate to false.
expr3 is evaluated every time except for the first time.
The for() loop is an entry-controlled loop.
Different constructs of for loop (these syntax are correct syntax)
•	 for( ;condition;)
		 {
		 Increment / decrement;
		 }
•	 for(i=0,j=0,k=100; i=200;i++,j++,k++)
		 {
		 }
•	 for(;i10;i++ )
		 {
		 }
•	 for(;i10;i++ );
		 {
		 }
[N.B.: These programs have been executed using Dev-C++ Version 5.11]
#includestdio.h
main()
{
Decision making and looping
47
/* printing the integers from 1 to 10 using a for() loop */
int i;
for(i=1;i11;i++)
{
printf(ni = %d, i);	
}
return 0;
}
6.2  The while () loop:
The general form of the while() loop is:
while (expr)
{
code-block;
}
If the expr after while evaluates to true then the body of the while() loop will be executed, otherwise control is transferred to the
statement following the while() loop body.
The while() loop is an entry-controlled loop, which implies that if the expr evaluates to false right at the beginning then the body
of the while loop will not be executed even once.
#includestdio.h
main()
{
/* printing the integers from 11 to 20 using a while() loop */
int j=11;
while(j21)
Computer Concepts and Fundamentals of Programming
48
{
printf(nj = %d, j);	
j++;
}
return 0;
}
6.3  The do... while() loop
The general form of the while() loop is:
do
{
code-block;
}while (expr);
If the expr after while evaluates to true then the body of the do... while() loop will be executed, otherwise control is transferred to
the statement following the while() loop body.
The body of the do... while(); loop will be necessarily executed at least once. The do... while() loop is an exit-controlled loop.
#includestdio.h
main()
{
/* printing the integers from 21 to 30 using a do...while() loop */
int k=21;
do
{
printf(nk = %d, k);	
k++;
Decision making and looping
49
}while(k=30);
return 0;
}
6.4  Difference between while and do while loop
while do while
It is entry controlled loop It is exit controlled loop
The may not be executed if the condition is false to start with The loop will executed at least once
while(condition)
{
Statement 1;
Statement 2 ;
Statement 3;
}
do
{
Statement 1;
Statement 2 ;
Statement 3;
} while(condition);
Sample program 6.1 Program to illustrate tribonacci series
#includestdio.h
int main()
{int num,a=0,b=1,c=2,d=0,i;
printf(nEnter the number:);
scanf(%d,num);
printf(%dt%dt%d,a,b,c);
for(i=3;inum;i++)
{
Computer Concepts and Fundamentals of Programming
50
d=a+b+c;
printf(t%d ,d);
a=b;
b=c;
c=d;
}
}
Sample program 6.2 Tetranacci series
#includestdio.h
int main()
{int num,a=0,b=1,c=2,d=3,e=0,i;
printf(nEnter the number:);
scanf(%d,num);
printf(%dt%dt%d,a,b,c);
for(i=3;inum;i++)
{
e=a+b+c+d;
printf(t%d ,e);
a=b;
b=c;
c=d;
d=e;
}
}
Sample program 6.3 Lucas series
#includestdio.h
main()
{
 int x,y,z,num;
 printf(Enter the limit of Lucas number: );
 scanf(%d,num);
 x=2;
 y=1;
 while(num=x)
 {
   printf( %d,x);
   z=x+y;
   x=y;
   y=z;
 }
Decision making and looping
51
}
Sample program 6.4 Palindrome number
#includestdio.h
void pal();
main()
{
pal();
}
void pal()
{
int n,x,mod,rev=0;
printf(nEnter No.);
scanf(%d,n);
x=n;
while(n)
{
mod=n%10;
rev=rev*10+mod;
n=n/10;
}
if(rev==x)
printf(n PAL n);
else
printf(n NOT PAL n);
}
Sample program 6.5 Special number
#includestdio.h
void sp();
main()
{
sp();
}
void sp()
{
int n,x,mod,sum=0,f;
printf(n Enter no.);
scanf(%d,n);
x=n;
int i;
while(n)
{
mod=n%10;
f=1;
Computer Concepts and Fundamentals of Programming
52
for(i=1;i=mod;i++)
f=f*i;
sum=sum+f;
n=n/10;
}
if(sum==x)
printf(n SPL);
else
printf(n NOT SPL);
}
Sample program 6.6 Write a program to check whether the number is n- Narcissistic number
#includestdio.h
main()
{
long int cube,n,mod,sum=0,temp;
printf(Enter the any number: );
scanf(%d,n);
cube=n*n*n;
temp=cube;
digit=0;
while(cube)
{
mod=cube%10;
digit++;
cube=cube/10;
}
cube=x;
while(cube)
{
mod=cube%10;
sum=sum+pow(mod,digit);
cube=cube/10;
}
if(sum==n)
printf(“The given number: = %d is a n- Narcissistic number”,sum);
else
printf(“The given number: = %d is a n- Narcissistic not number”,sum);
}
Sample program 6.7 Armstrong number is also n- Narcissistic page
#includestdio.h
main()
{	 int mod,n,x,arm1=0;
	 printf(enter the val of n);
Decision making and looping
53
	scanf(%d,n);
	x=n;
	while(n)
	{
mod=n%10;
	arm1=arm1+mod*mod*mod;
	n=n/10;
	}
if(arm1==x)
printf(nnyes armstrong hai!!!!!nn);
else
printf(nnyes armstrong nahi hai!!!!!nn);
}
Sample program 6.8 Write a program to check whether the number is Prime number or not
#includestdio.h
main()
{
int n, i = 3, count, c;
printf(Enter the number of prime numbers requiredn);
scanf(%d,n);
if ( n = 1 )
{
printf(First %d prime numbers are:n,n);
printf(2n);
}
for ( count = 2 ; count = n ; )
{
for ( c = 2 ; c = i - 1 ; c++ )
{
if ( i%c == 0 )
break;
}
if ( c == i )
{
printf(%dn,i);
count++;
}
i++;
}
}
Sample program 6.9 Write a program to check whether the entered number is a.Magic number or not
//magic number 82=8+2=10=1+0=1
Computer Concepts and Fundamentals of Programming
54
#includestdio.h
main()
{
int n,x,mod,rev=0;
printf(nEnter the limitn);
scanf(%d,n);
TMI:
for(x=n;n;n=n/10)
{mod=n%10;rev+=mod;}
if(rev=10)
{n=rev;rev=0;
goto TMI;
}
else if(rev==1)
printf(Entered number is a magic no );
else
printf(Entered number is not a magic no );
}
Sample program 6.10 Write a program to print the following Pattern
/*
					 *
					 * *
					 * * *
					 * * * *
					 * * * * *
			*/
			#includestdio.h
			main()
			{
				 int n,i,j,k,l;
				 printf(nEnter the limitn);
				 scanf(%d,n);
			 // work for the rows
			for(i=1;i=n;i++)
			{
			for(k=1;k=10000000;k++);
			 for(l=40;l=i;l--)// work for the spaces
			{printf( );}
			for(j=1;j=i;j++)
			{printf( *);}
			printf(n);
			}
			}
Decision making and looping
55
6.5  Programs for practice
1.	 WAP to find and print the sum of digits of a number entered by user.
2.	 WAP to find and print the greatest digit of a number entered by user.
3.	 WAP to find and print the smallest digit of a number entered by user.
4.	 WAP to find and print all even digits of a number entered by user.
5.	 WAP to Print the square root of each digit of any number. Consider each digit as perfect square. For example 494 the square
roots to be printed should be 232.
6.	 WAP to enter two integer values through keyboard. Using while loop, perform the product of the two integers. In case
product is zero, loop should be terminated otherwise loop will continue.
7.	 To enter integer number and find the largest and smallest digit of that number based on user choice.
8.	 To find and print the Fibonacci series till n where n is user defined.
9.	 To condense the number to a single digit.
10.	 To check whether the number entered by user is Arm-strong number or not.
11.	 To check whether the number entered by user is perfect number or not.
12.	 To check whether the number entered by user is magic number or not.
13.	 To check whether the number entered by user is palindrome number or not.
14.	 To check whether the number entered by user is special number or not.
15.	 To find and print the Factorial of a number entered by user.
16.	 Write a program in ‘C’ to generate the following output:
(a).
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
(b).
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
(c).
5 4 3 2 1
5 4 3 2
5 4 3
5 4
(d).
*
**
***
Computer Concepts and Fundamentals of Programming
56
****
*****
****
***
**
*
(e).
C
CO
COM
COMP
COMPU
COMPUT
COMPUTE
(f).
C
COO
COOMMM
COOMMMPPPP
COOMMMPPPPUUUUU
COOMMMPPPPUUUUUTTTTTT
COOMMMPPPPUUUUUTTTTTTEEEEEEE
(g).
C
CCO
CCCOOM
CCCCOOOMMP
CCCCCOOOOMMMPPU
CCCCCCOOOOOMMMMPPPUUT
CCCCCCCOOOOOOMMMMMPPPPUUUTTE
(h).
C
CCOO
CCCOOOMMM
CCCCOOOOMMMMPPPP
CCCCCOOOOOMMMMMPPPPPUUUUU
CCCCCCOOOOOOMMMMMMPPPPPPUUUUUUTTTTTT
CCCCCCCOOOOOOOMMMMMMMPPPPPPPUUUUUUUTTTTTTTEEEEEEE
Decision making and looping
57
(i).
1
121
12321
1234321
123454321
12345654321
1234567654321
(j).
9
989
98789
9876789
987656789
98765456789
9876543456789
987654323456789
98765432123456789
(k)
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
(l).
1
23
456
78910
(m).
(
)(
)()
()()
()()(
(n).
1
Computer Concepts and Fundamentals of Programming
58
232
34543
4567654
567898765
(o).
1
232
34543
4567654
567898765
67890109876
7890123210987
890123454321098
CHAPTER – 7
ARRAYS
7.1 Arrays
Suppose we want to obtain 10 integer values, perform mathematical or other operations on them and then print the results, then
we might require ten integer variables: var1, var2, var3,... , var10, for instance.
Several programming languages provide the concept of arrays which help in reducing the number of variables because of a common
name and indices for referencing individual elements.
Let us consider an example:
#includestdio.h
main()
{
	 int num[10];
	 int i;
	
	 printf(nNow obtaining 10 integer values: n);
	for(i=0;i10;i++)
	{
		 printf(Enter %dth integer: , i);
		scanf(%d, num[i]);
	}
	
	 printf(nThe 10 integer values which you entered are as follows:);
	for(i=0;i10;i++)
		 printf(nnum[%d] = %d, i, num[i]);
		
	 return 0;
}
Computer Concepts and Fundamentals of Programming
60
A sample interaction with the program might appear as follows:
How arrays are stored in memory?
The declaration
	 int num[10];
indicates to the ‘C’ compiler that memory is to be reserved (continuous locations) for storing 10 integer values.
The locations are individually identified as num[0], num[1], num[2],... , num[9]. If an integer requires 4 bytes for storage, and if
the first integer is being stored in locations identified as 2358932, 2358933, 2358934, 2358935; then the second integer would be
stored in the locations: 2358936, 2358937, 2358938 and 2358939. In the diagram below, the numbers on the right indicate the
address of the individual array elements.
num[0] 2358932
num[1] 2358936
num[2] 2358940
num[3] 2358944
num[4] 2358948
num[5] 2358952
num[6] 2358956
num[7] 2358960
num[8] 2358964
num[9] 2358968
A few important points pertaining to arrays:
If an array is declared as:
Arrays
61
	 int num[10];
	 (i) then the first element of the array will be referred to as num[0] and the last element of the array will be referred to as
num[9];
	 (ii) If an array is declared as a global array [above main() ], then
		 (a) It will be initialized with NULL values in case it is a char type array
		 (b) It will be initialized with 0 (zero) in case it is a numeric array
	 (iii) If an array is declared as a static array, then
		 (a) It will be initialized with NULL values in case it is a char type array
		 (b) It will be initialized with 0 (zero) in case it is a numeric array
	 (iv) If a numeric type array is partially initialized at the place where it is declared, then the rest of the elements are
automatically set to zero.
	 (v) An array name is a pointer to itself. Thus num[0] and num would be the same.
Two-dimensional arrays
A declaration such as:
	 int num[4][5];
creates an array of 4 rows and 5 columns and might be visualized as follows:
Col 0 Col 1 Col 2 Col 3 Col 4
Row 0
Row 1
Row 2
Row 3
The individual elements might be accessed as follows:
num[0][0] num[0][1] num[0][2] num[0][3] num[0][4]
num[1][0] num[1][1] num[1][2] num[1][3] num[1][4]
num[2][0] num[2][1] num[2][2] num[2][3] num[2][4]
num[3][0] num[3][1] num[3][2] num[3][3] num[3][4]
The program below demonstrates how to enter values into a two-dimensional array and then print the values.
#includestdio.h
#define ROWS 3
#define COLS 4
main()
{
int mat[ROWS][COLS];
int i, j;
printf(nNow obtaining integers for %d X %d matrix:n, ROWS, COLS);
for(i=0;iROWS;i++)
Computer Concepts and Fundamentals of Programming
62
{
	for(j=0;jCOLS;j++)
	{
	 printf(Enter integer for %dth row and %dth column: ,i,j);
	 scanf(%d, mat[i][j]);
	}
}
	 printf(nThe matrix is as follows:n);
	for(i=0;iROWS;i++)
	{
	 	 for(j=0;jCOLS;j++)
	 	{
		 printf(%8d, mat[i][j]);
		}
printf(n);
}
printf(nThe addresses of the matrix elements are as follows:n);
printf(nAddress (matrix element)n);
for(i=0;iROWS;i++)
{
	for(j=0;jCOLS;j++)
	{
	 printf(%u (%d) , mat[i][j], mat[i][j]);
	}
printf(n);
}
return 0;
}
Arrays
63
A sample output is shown below:
Sample program 7.1 Program to illustrate matrix multiplication of two matrices of same order Matrix multiplication
#include stdio.h
main()
{
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];
printf(Enter the number of rows and columns of first matrixn);
scanf(%d%d, m, n);
printf(Enter the elements of first matrixn);
for ( c = 0 ; c  m ; c++ )
for ( d = 0 ; d  n ; d++ )
scanf(%d, first[c][d]);
printf(Enter the number of rows and columns of second matrixn);
scanf(%d%d, p, q);
if ( n != p )
printf(Matrices with entered orders can't be multiplied with each other.n);
else
{
printf(Enter the elements of second matrixn);
for ( c = 0 ; c  p ; c++ )
Computer Concepts and Fundamentals of Programming
64
for ( d = 0 ; d  q ; d++ )
scanf(%d, second[c][d]);
for ( c = 0 ; c  m ; c++ )
{
for ( d = 0 ; d  q ; d++ )
{
for ( k = 0 ; k  p ; k++ )
{
	 sum = sum + first[c][k]*second[k][d];
}
multiply[c][d] = sum;
sum = 0;
}
}
printf(Product of entered matrices:-n);
for ( c = 0 ; c  m ; c++ )
{
for ( d = 0 ; d  q ; d++ )
printf(%dt, multiply[c][d]);
printf(n);
}
}
}
Sample program 7.2 Write a first category function program to read a two matrices A and B of order 9x9 and print the
following.
a)A+B and
b)A-B
#includestdio.h
main()
{ int a[3][3],b[3][3],c[3][3],i,j;
printf(Enter the First 3x3 Matrix: );
for(i=0;i3;i++)
{
for(j=0;j3;j++)
scanf(%d,a[i][j]);
}
printf(Enter the Second 3x3 Matrix: );
for(i=0;i3;i++)
{ for(j=0;j3;j++)
scanf(%d,b[i][j]);
}
printf(nThe Sum of Matrices is: );
for(i=0;i3;i++)
Arrays
65
{
printf(n);
for(j=0;j3;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf(%d ,c[i][j]);
}
}
printf(nnThe Difference of Matrices is: );
for(i=0;i3;i++)
{
printf(n);
for(j=0;j3;j++)
{ c[i][j]=a[i][j]b[
i][j]; //2 mark
printf(%d ,c[i][j]);
}
}
}
Sample program 7.3 Write a program that will put 8 queens on a Chessboard so that no queen can capture another. The size
of the board is 8 x 8. One queen can capture another if it is standing in the same row (horizontal), or in the same column
(vertical), or on the same diagonal as the other queen.
#includestdio.h
#includemath.h
int a[30],count=0;
int place(int pos)
{
int i;
for(i=1;ipos;i++)
{
if((a[i]==a[pos])||((abs(a[i]a[pos])==abs(ipos))))
return 0;
}
return 1;
}
void print_sol(int n)
{
int i,j;
count++;
printf(nnSolution #%d:n,count);
Computer Concepts and Fundamentals of Programming
66
for(i=1;i=n;i++)
{
for(j=1;j=n;j++)
{
if(a[i]==j)
printf(Qt);
else
printf(*t);
}
printf(n);
}
}
void queen(int n) //1 mark
{
int k=1;
a[k]=0;
while(k!=0)
{
a[k]=a[k]+1;
while((a[k]=n)!place(k)) //1 mark
a[k]++;
if(a[k]=n) //1 mark
{
if(k==n)
print_sol(n);
else
{
k++;
a[k]=0; //1 mark
}
}
else
k;
}
}
main() //1 mark
{
int i,n;
printf(Enter the number of Queensn);
scanf(%d,n);
Arrays
67
queen(n);
printf(nTotal solutions=%d,count);
}
Selection Sort
In Selection Sort, the element at the zeroth position is compared with all the elements below it and an interchange performed
as and when required (depending on whether the elements have to be arranged in ascending or descending order). Thereafter,
the element at the first position is compared with all the elements below it and an interchange performed as and when required.
Similarly, the elements at the second, third,... position are compared with all the elements below them and an interchange
performed as and when required. The program below is an implementation of Selection Sort:
#includestdio.h
#define SIZE 10
main()
{
	 int array[SIZE];
	 int i, j, t;
	 printf(nNow obtaining %d integers: n, SIZE);
	for(i=0;iSIZE;i++)
	{
		 printf(Enter %dth integer: , i);
		scanf(%d, array[i]);
	}
	 printf(nnBefore sorting:);
	for(i=0;iSIZE;i++)
	 printf(n%d, array[i]);
	for(i=0;iSIZE-1;i++)
	{
		for(j=i+1;jSIZE;j++)
		{
			if(array[i]array[j])
			{
				t=array[i];
				array[i]=array[j];
				array[j]=t;
			}
		}
	}
	 printf(nnAfter sorting:);
	for(i=0;iSIZE;i++)
	 printf(n%d, array[i]);
	 return 0;
}
Computer Concepts and Fundamentals of Programming
68
A sample output is shown below:
Bubble sort
In Bubble sort two successive elements are compared with each other and an interchange performed as and when required
(depending on whether sorting is required in ascending or descending order).
#includestdio.h
#define SIZE 10
main()
{
	 int num[SIZE];
	 int i, j;
	 int t;
	
	for(i=0;iSIZE;i++)
	{
Arrays
69
		 printf(Enter %dth integer: , i);
		scanf(%d, num[i]);
	}
	 printf(nBefore sorting: );
	 for(i=0;iSIZE;i++)
	 printf(n%d, num[i]);
	for(i=0;iSIZE-1;i++)
	{
		for(j=0;jSIZE-1;j++)
		{
			if(num[j]num[j+1])
			{
				t = num[j];
				num[j]=num[j+1];
				num[j+1]=t;
			}
		}
	}
	 printf(nAfter sorting: );
	for(i=0;iSIZE;i++)
	 printf(n%d, num[i]);
	 return 0;
}
Computer Concepts and Fundamentals of Programming
70
A sample output is shown below:
Suppose the integers are entered in the following order:
9012
481
916
-9129
0
-873
3782
6712
-865
-2
After 0th run of the outer for(i...) loop
481
916
-9129
Arrays
71
0
-873
3782
6712
-865
-2
9012 (The largest integer in the array is at the bottom of the array)
After 1th run of the outer for(i...) loop
481
-9129
0
-873
916
3782
-865
-2
6712 (The second highest integer in the array is in the second last position in the array)
9012
After 2th run of the outer for(i...) loop
-9129
0
-873
481
916
-865
-2
3782 (The third highest integer in the array is in the third last position in the array)
6712
9012
After 3th run of the outer for(i...) loop
-9129
-873
0
481
-865
-2
916
Computer Concepts and Fundamentals of Programming
72
3782
6712
9012
After 4th run of the outer for(i...) loop
-9129
-873
0
-865
-2
481
916
3782
6712
9012
After 5th run of the outer for(i...) loop
-9129
-873
-865
-2
0
481
916
3782
6712
9012
After 6th run of the outer for(i...) loop
-9129
-873
-865
-2
0
481
916
3782
6712
9012
After 7th run of the outer for(i...) loop
Arrays
73
-9129
-873
-865
-2
0
481
916
3782
6712
9012
After 8th run of the outer for(i...) loop
-9129
-873
-865
-2
0
481
916
3782
6712
9012
After sorting:
-9129
-873
-865
-2
0
481
916
3782
6712
9012
7.3  Programs for practice
1.	 To read 10 integers in an array and print all the values stored in the array.
2.	 To read 10 integers in an array and print all the values in reverse order stored in the array.
3.	 To read 10 integers in an array and Find the largest and smallest number from the array.
4.	 To read 10 fractions in an array and print alternate array elements.
Computer Concepts and Fundamentals of Programming
74
5.	 To print all even numbers stored in an array of size n, where n is user defined.
6.	 To accept an array of n elements, n user defined. Increase each value by 100 and print the new array.
7.	 To read 10 integers in an array. Find and print the largest and smallest number.
8.	 To accept an array of n numbers. Check value, if an even number is found, increase its value by 10, if odd decrease its value
by 5and print both odd as well as new array.
9.	 To find and print all arm-strong numbers stored in an array of size n, where n is user defined.
10.	 To find and print all prime numbers stored in an array of size n, where n is user defined.
11.	 To find sum and average of any n values stored in an array.
12.	 To accept any n value,store them in the array and check the presence of any number entered by user in the array. If present,
print the number, its first location and how many times it occurs in the array.
13.	 To read a number containing five digits. Perform square of each digit.
14.	 To read a number of any length. Perform the addition and subtraction on largest and smallest digits of it
CHAPTER – 8
STRINGS
String functions in ‘C’
In ‘C’ language a string is an array of characters terminated by ‘0’ (the null character).
Some of the most commonly used string functions in ‘C’ are:
strcat(): for concatenating two strings,
strchr(): used for locating the first occurrence of the character (second argument) in the string (first argument),
strcmp(): used for comparing two strings,
strcpy(): used for copying the string contained as the second argument to the function, in the first argument to the function,
strncpy(): used for avoiding buffer overflow when copying,
strlen(): for computing the length of the string,
strncat(): for appending n bytes,
strlwr(): for converting a string to lowercase
strupr(): for converting a string to uppercase
The programs below demonstrate the use of a few string functions.
#includestdio.h
#includestring.h
main()
{
	 char str[80];
	 printf(nEnter any string:);
	 scanf(%[^n], str);
	 printf(nstr = %s, str);
	 printf(nstrlwr(str) = %s, strlwr(str));
	 printf(nstrupr(str) = %s, strupr(str));
	 printf(nstrlen(str) = %d, strlen(str));
return 0;
}
Computer Concepts and Fundamentals of Programming
76
A sample output is shown below:
#includestdio.h
#includestring.h
main()
{
	 char str1[] = Sky is the limit;
	 char str2[] = Sky is Not the limit;
	 char str3[80] =  ;
	 int result;
	 printf(nnstr1 = %s, str1);
	 printf(nnstr2 = %s, str2);
	 printf(nnstr3 = %s, str3);
	 strcpy(str3, str2); /*strcpy(destination, source)*/
printf(nnAfter copying str2 to str3, str3 = %s, str3);
result = strcmp(str1, str2);
/* strcmp(str1, str2) returns a value  0 if str1 alphabetically precedes str2,
strcmp(str1, str2) returns a value  0 if str2 alphabetically precedes str1,
strcmp(str1, str2) returns 0 if str1 is exactly the same as str2 */
printf(nnOn comparing str1 and str2, result = %d, result);
	 return 0;	
}
Strings
77
A sample output is shown below:
const char* strstr(const char *str1, const char *str2);
The strstr() function returns a pointer to the first occurrence of str2 in str1, or a null pointer if str2 is not a subset of str1.
A program illustrating the use of strstr() follows:
#includestdio.h
#includestring.h
main()
{
	 char str1[] = Sky is the limit;
	 char *result;
	 printf(nnstr1 = %s, str1);
	 result= strstr(str1, the);
	 printf(nnresult = %s, result);
	 result= strstr(str1, star);
	 printf(nnresult = %s, result);
	 return 0;	
}
A sample output is shown below:
str1 = Sky is the limit
result = the limit
result = (null)
Computer Concepts and Fundamentals of Programming
78
Sample program 8.1.Write a program to enter a paragraph and check number of alphabet, digit or special character
/* C program to check alphabet, digit or special character */
#include stdio.h
main()
{
char ch;
/* Reads a character from user */
printf(Enter any character: );
scanf(%c, ch);
/* Checks if it is an alphabet */
if((ch = 'a'  ch = 'z') || (ch = 'A'  ch = 'Z'))
{
printf(%c is ALPHABET.n, ch);
}
else if(ch = '0'  ch = '9')
{
printf(%c is DIGIT.n, ch);
}
else
{ printf(%c is SPECIAL CHARACTER.n, ch);
}
}
8.3  Programs for practice
1.	 To accept a matrix of mXn order, n and m are user defined, from user. Calculate and print their row sum, column sum and
diagonal sum.
2.	 To accept a matrix of mXn order, where n and m are user defined, from user. Print its transpose.
3.	 To accept any string from user and print its length.
4.	 To accept any string from user and print the string in reverse order.
5.	 To accept any string from user and insert any n characters from mth position from it. ( n and m should be less than length
of the string )
6.	 Read a set of 5 lines from user and print out the longest line.
CHAPTER – 9
USER DEFINED FUNCTIONS
9.1 Definition
Self-contained block of statement used to perform a particular task is called as function. The biggest advantage of function is code
reusability. It divides the large program into segments because of this it becomes easy for a programmer to debug the program.
Functions are sometimes called as methods. Functions are divided into following category
i.	 Call by value and
ii.	 Call by reference/ call by address:
	 i.	Call by value: In this category of the function the copy of variable value is being passed to the called function. This
divided into following categories depending on the return type and parameter it carries.
1.	 Function with no return and parameter
2.	 Function with no return but carrying parameter
3.	 Function with return but carrying no parameter
4.	 Function with return as well as parameter
	 ii.	 Call by reference / call by address:
	 In this category of function the address of the variable is passed to the called function. Sometime address is also called
as reference of variable.
Program 9.1 Call by value: Function category 1: Write a program to perform addition of two numbers.
#includestdio.h
#includeconio.h
void add(void);
main()
{
add();
}
void add()
{
int a,b,c;
printf(enter the value of a,b);
scanf(%d%d,a,b);
c=a+b;
printf(n addition is: =);
printf(%d,c);
}
Computer Concepts and Fundamentals of Programming
80
Note: Same program can be written by using fourth category
9.2 Call by value: Function category 4: Write a program to perform addition of two numbers.
#include stdio.h
#include conio.h
int ganesh(int a,int b);
main()
{ int x=4,y=8,z;
z=ganesh(x,y); // here x and y are called as actual parameter ,ssss
printf(%d,z);
}
int ganesh(a,b)// here a and b are called as formal parameters
{
int c=a+b;
return c;
}
9.3 Call by reference: Write a function program with call by reference to swap the values of two integer variable.
In call by reference, the operation performed on formal parameters, affects the value of actual parameters because all the operations
performed on the value stored in the address of actual parameters.
#include stdio.h
#include conio.h
void swapnum ( int *var1, int *var2 )
{
int tempnum ;
tempnum = *var1 ;
*var1 = *var2 ;
*var2 = tempnum ;
}
int main( )
{
int num1 = 35, num2 = 45 ;
printf(Before swapping:);
printf(nnum1 value is %d, num1);
printf(nnum2 value is %d, num2);
/*calling swap function*/
swapnum( num1, num2 );
printf(nAfter swapping:);
printf(nnum1 value is %d, num1);
printf(nnum2 value is %d, num2);
getch();
return 0;
}
User defined function
81
9.3  Parameter and its types
Parameters are nothing but the variables. Depending upon the location of the declaration they are classified as:
1.	 Local parameter: Any variable declared within the function body is a local parameter. Its scope lies up to that function
body only where it is declared.
2.	 Global parameter: Any viable declared outside the function body is called as global parameter.
3.	 Actual parameter: The parameter which are being passed to the called function are calle as actual parameter.
4.	 Formal parameter: The parameter which are accepting the value of actual parameter are called as formal parameter.
Following example best illustrates the functioning of the different parameters
#include stdio.h
#include conio.h
int pi;// This is a global variable
int ganesh(int a,int b);
main()
{ int x=4,y=8,z;// x,y,z atre called as local parameter
z=ganesh(x,y); // here x and y are called as actual parameter, ssss
printf(%d,z);
}
int ganesh(a,b)// here a and b are called as formal parameters
{
int c=a+b;
return c;
}
9.4 Recursion
Recursion: Function which is called within its own body is called as recursion.
Program 8.3.1
//This program is for the recusive function
//function called within its own body
#includestdio.h
main()
{
	 printf(nThis is a recursive function will run infinitenn);
	main();
}
9.3.2  Program Fibonacci series
/*This program is showing the execution of recusive function*/
#includestdio.h
Computer Concepts and Fundamentals of Programming
82
#includeconio.h
int Fibonacci(int);
int main()
{
int n, i = 0, c;
scanf(%d,n);
printf(Fibonacci seriesn);
for ( c = 1 ; c = n ; c++ )
{
printf(%dn, Fibonacci(i));
i++;
}
return 0;
}
int Fibonacci(int n)
{
if ( n == 0 )
return 0;
else if ( n == 1 )
return 1;
else
return ( Fibonacci(n-1) + Fibonacci(n-2) );
}
9.4  Programs for practice
WAP to check whether the given number is (Using all the four categories of function)
1.	 PRIME NUMBER
2.	 ARMSTRONG NUMBER
3.	 PALINDROME NUMBER
4.	 SPECIAL NUMBER
5.	 MAGIC NUMBER
6.	 PERFECT NUMBER
7.	 ADAM NUMBER
CHAPTER – 10
POINTERS
10.1 Introduction
The computer’s memory is a collection of storage cell. Each cell or location has a unique address. The address is a consecutive
numerical number often expressed in hexadecimal, which is difficult to use directly in the program. To ease the burden of
programming using numerical address, the concept of variables is introduced. A variable is a named location that can store a value
of a particular type. Instead of numerical addresses, names are attached to certain addresses. Also, data types such as int, double,
char are related with the contents for the interpretation of data.
Pointer is defined as address variable, a variable which holds the address of another variable.
The following diagram illustrate the relationship between computers' memory address and content; and variable's name and value
used by the programmers.
Address Name Value /content
7000000
7000001 a 25
7000002
7000003
7000004 b 3
7000005
	 int a=25, b=3;
7000001 is the address of variable named “a” whose value is 25. If this address 7000001 is be stored in a variable, then
the variable has to be a pointer or pointer variable.
10.2  Pointer declaration
Like any other variable the pointer variable also should be declared before use.
Syntax to declare a pointer
	 data_type * pointer_var_name;
Example
	 int * p;
The character asterisk (*) tells to the compiler that the identifier “p” should be declare as pointer. The data type tells to the compiler
that pointer “p” will store memory address of an integer variable.
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING
COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING

More Related Content

What's hot

Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programmingavikdhupar
 
Representation of binary tree in memory
Representation of binary tree in memoryRepresentation of binary tree in memory
Representation of binary tree in memoryRohini Shinde
 
Fixed point and floating-point numbers
Fixed point and  floating-point numbersFixed point and  floating-point numbers
Fixed point and floating-point numbersMOHAN MOHAN
 
Data Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of HanoiData Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of HanoiManishPrajapati78
 
Data representation
Data representationData representation
Data representationMysore
 
Computer organisation -morris mano
Computer organisation  -morris manoComputer organisation  -morris mano
Computer organisation -morris manovishnu murthy
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in cPrabhu Govind
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILEDipta Saha
 
Digital electronics- BCD & Decoder
Digital electronics- BCD & DecoderDigital electronics- BCD & Decoder
Digital electronics- BCD & DecoderPritam Shil
 
Shift micro operations & 4 bit combinational circuit shifter
Shift micro operations &  4 bit combinational circuit shifterShift micro operations &  4 bit combinational circuit shifter
Shift micro operations & 4 bit combinational circuit shifterMonika Chauhan
 
Memory Reference Instructions | Computer Science
Memory Reference Instructions | Computer ScienceMemory Reference Instructions | Computer Science
Memory Reference Instructions | Computer ScienceTransweb Global Inc
 
Input output organization
Input output organizationInput output organization
Input output organizationabdulugc
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C LanguageRAJWANT KAUR
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTUREArchie Jamwal
 
Computer registers
Computer registersComputer registers
Computer registersDeepikaT13
 
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patilwidespreadpromotion
 

What's hot (20)

Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
BCD Counter
BCD CounterBCD Counter
BCD Counter
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
Representation of binary tree in memory
Representation of binary tree in memoryRepresentation of binary tree in memory
Representation of binary tree in memory
 
Fixed point and floating-point numbers
Fixed point and  floating-point numbersFixed point and  floating-point numbers
Fixed point and floating-point numbers
 
Data Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of HanoiData Structure and Algorithms The Tower of Hanoi
Data Structure and Algorithms The Tower of Hanoi
 
Data representation
Data representationData representation
Data representation
 
Computer organisation -morris mano
Computer organisation  -morris manoComputer organisation  -morris mano
Computer organisation -morris mano
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
 
Digital electronics- BCD & Decoder
Digital electronics- BCD & DecoderDigital electronics- BCD & Decoder
Digital electronics- BCD & Decoder
 
Shift micro operations & 4 bit combinational circuit shifter
Shift micro operations &  4 bit combinational circuit shifterShift micro operations &  4 bit combinational circuit shifter
Shift micro operations & 4 bit combinational circuit shifter
 
Memory Reference Instructions | Computer Science
Memory Reference Instructions | Computer ScienceMemory Reference Instructions | Computer Science
Memory Reference Instructions | Computer Science
 
Basic Computer Organization and Design
Basic  Computer  Organization  and  DesignBasic  Computer  Organization  and  Design
Basic Computer Organization and Design
 
INPUT OUTPUT MEMORY DEVICE.pdf
INPUT OUTPUT MEMORY DEVICE.pdfINPUT OUTPUT MEMORY DEVICE.pdf
INPUT OUTPUT MEMORY DEVICE.pdf
 
Input output organization
Input output organizationInput output organization
Input output organization
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Computer registers
Computer registersComputer registers
Computer registers
 
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
 

Similar to COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING

Lecture1.pdf
Lecture1.pdfLecture1.pdf
Lecture1.pdfJoyPalit
 
A computer system chapter presentation new full typed
A computer system chapter presentation new full typedA computer system chapter presentation new full typed
A computer system chapter presentation new full typedsmrutiranjan lenka
 
It tools & technology
It tools & technologyIt tools & technology
It tools & technologyJIGAR MAKHIJA
 
top LLB university in Delhi NCR.pdf
top LLB university in Delhi NCR.pdftop LLB university in Delhi NCR.pdf
top LLB university in Delhi NCR.pdfOpjsuniversity1
 
Computer Fundamentals
Computer FundamentalsComputer Fundamentals
Computer FundamentalsMudit Khetan
 
Introduction to Information Systems Canadian 4th Edition Rainer Solutions Manual
Introduction to Information Systems Canadian 4th Edition Rainer Solutions ManualIntroduction to Information Systems Canadian 4th Edition Rainer Solutions Manual
Introduction to Information Systems Canadian 4th Edition Rainer Solutions ManualBradleyNoels
 
Atharva Patil_28_9th lilies_Computer Project2.pptx
Atharva Patil_28_9th lilies_Computer Project2.pptxAtharva Patil_28_9th lilies_Computer Project2.pptx
Atharva Patil_28_9th lilies_Computer Project2.pptxAtharvaPatil48
 
computer application in hospitality Industry, periyar university unit 1
computer application in hospitality Industry, periyar university  unit 1computer application in hospitality Industry, periyar university  unit 1
computer application in hospitality Industry, periyar university unit 1admin information
 
computer applicationin hospitality Industry1 periyar university unit1
computer applicationin hospitality Industry1 periyar university  unit1computer applicationin hospitality Industry1 periyar university  unit1
computer applicationin hospitality Industry1 periyar university unit1admin information
 
performing computer operations.pptx
performing computer operations.pptxperforming computer operations.pptx
performing computer operations.pptxCARMELINEPRECYLLORCA
 
INTRODUCTION TO COMPUTER .pptx
INTRODUCTION TO COMPUTER .pptxINTRODUCTION TO COMPUTER .pptx
INTRODUCTION TO COMPUTER .pptxRamjeyDavocRony
 
Fundamentals of Information and communication technology.pptx
Fundamentals of Information and communication technology.pptxFundamentals of Information and communication technology.pptx
Fundamentals of Information and communication technology.pptxrilaghost
 

Similar to COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING (20)

Lecture1.pdf
Lecture1.pdfLecture1.pdf
Lecture1.pdf
 
A computer system chapter presentation new full typed
A computer system chapter presentation new full typedA computer system chapter presentation new full typed
A computer system chapter presentation new full typed
 
It tools & technology
It tools & technologyIt tools & technology
It tools & technology
 
top LLB university in Delhi NCR.pdf
top LLB university in Delhi NCR.pdftop LLB university in Delhi NCR.pdf
top LLB university in Delhi NCR.pdf
 
Computer Fundamentals
Computer FundamentalsComputer Fundamentals
Computer Fundamentals
 
Problem solving in C.ppt
Problem solving in C.pptProblem solving in C.ppt
Problem solving in C.ppt
 
Generation of computer
Generation of computerGeneration of computer
Generation of computer
 
Introduction to Information Systems Canadian 4th Edition Rainer Solutions Manual
Introduction to Information Systems Canadian 4th Edition Rainer Solutions ManualIntroduction to Information Systems Canadian 4th Edition Rainer Solutions Manual
Introduction to Information Systems Canadian 4th Edition Rainer Solutions Manual
 
Atharva Patil_28_9th lilies_Computer Project2.pptx
Atharva Patil_28_9th lilies_Computer Project2.pptxAtharva Patil_28_9th lilies_Computer Project2.pptx
Atharva Patil_28_9th lilies_Computer Project2.pptx
 
It advance 2016
It advance 2016It advance 2016
It advance 2016
 
I learning lot
I learning lotI learning lot
I learning lot
 
Unit i
Unit  iUnit  i
Unit i
 
computer application in hospitality Industry, periyar university unit 1
computer application in hospitality Industry, periyar university  unit 1computer application in hospitality Industry, periyar university  unit 1
computer application in hospitality Industry, periyar university unit 1
 
computer applicationin hospitality Industry1 periyar university unit1
computer applicationin hospitality Industry1 periyar university  unit1computer applicationin hospitality Industry1 periyar university  unit1
computer applicationin hospitality Industry1 periyar university unit1
 
Unit I
Unit  IUnit  I
Unit I
 
Unit i
Unit  iUnit  i
Unit i
 
performing computer operations.pptx
performing computer operations.pptxperforming computer operations.pptx
performing computer operations.pptx
 
Topic 1 - Overview of IT.pdf
Topic 1 - Overview of IT.pdfTopic 1 - Overview of IT.pdf
Topic 1 - Overview of IT.pdf
 
INTRODUCTION TO COMPUTER .pptx
INTRODUCTION TO COMPUTER .pptxINTRODUCTION TO COMPUTER .pptx
INTRODUCTION TO COMPUTER .pptx
 
Fundamentals of Information and communication technology.pptx
Fundamentals of Information and communication technology.pptxFundamentals of Information and communication technology.pptx
Fundamentals of Information and communication technology.pptx
 

More from Infinity Tech Solutions

Database Management System-session 3-4-5
Database Management System-session 3-4-5Database Management System-session 3-4-5
Database Management System-session 3-4-5Infinity Tech Solutions
 
Main topic 3 problem solving and office automation
Main topic 3 problem solving and office automationMain topic 3 problem solving and office automation
Main topic 3 problem solving and office automationInfinity Tech Solutions
 
Computer memory, Types of programming languages
Computer memory, Types of programming languagesComputer memory, Types of programming languages
Computer memory, Types of programming languagesInfinity Tech Solutions
 
AI/ML/DL/BCT A Revolution in Maritime Sector
AI/ML/DL/BCT A Revolution in Maritime SectorAI/ML/DL/BCT A Revolution in Maritime Sector
AI/ML/DL/BCT A Revolution in Maritime SectorInfinity Tech Solutions
 
Programming with matlab session 5 looping
Programming with matlab session 5 loopingProgramming with matlab session 5 looping
Programming with matlab session 5 loopingInfinity Tech Solutions
 

More from Infinity Tech Solutions (20)

Database management system session 6
Database management system session 6Database management system session 6
Database management system session 6
 
Database management system session 5
Database management system session 5Database management system session 5
Database management system session 5
 
Database Management System-session 3-4-5
Database Management System-session 3-4-5Database Management System-session 3-4-5
Database Management System-session 3-4-5
 
Database Management System-session1-2
Database Management System-session1-2Database Management System-session1-2
Database Management System-session1-2
 
Main topic 3 problem solving and office automation
Main topic 3 problem solving and office automationMain topic 3 problem solving and office automation
Main topic 3 problem solving and office automation
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
E commerce
E commerce E commerce
E commerce
 
E commerce
E commerceE commerce
E commerce
 
Bds session 13 14
Bds session 13 14Bds session 13 14
Bds session 13 14
 
Computer memory, Types of programming languages
Computer memory, Types of programming languagesComputer memory, Types of programming languages
Computer memory, Types of programming languages
 
Basic hardware familiarization
Basic hardware familiarizationBasic hardware familiarization
Basic hardware familiarization
 
User defined functions in matlab
User defined functions in  matlabUser defined functions in  matlab
User defined functions in matlab
 
Programming with matlab session 6
Programming with matlab session 6Programming with matlab session 6
Programming with matlab session 6
 
Programming with matlab session 3 notes
Programming with matlab session 3 notesProgramming with matlab session 3 notes
Programming with matlab session 3 notes
 
AI/ML/DL/BCT A Revolution in Maritime Sector
AI/ML/DL/BCT A Revolution in Maritime SectorAI/ML/DL/BCT A Revolution in Maritime Sector
AI/ML/DL/BCT A Revolution in Maritime Sector
 
Programming with matlab session 5 looping
Programming with matlab session 5 loopingProgramming with matlab session 5 looping
Programming with matlab session 5 looping
 
BIG DATA Session 7 8
BIG DATA Session 7 8BIG DATA Session 7 8
BIG DATA Session 7 8
 
BIG DATA Session 6
BIG DATA Session 6BIG DATA Session 6
BIG DATA Session 6
 
MS word
MS word MS word
MS word
 
DBMS CS 4-5
DBMS CS 4-5DBMS CS 4-5
DBMS CS 4-5
 

Recently uploaded

Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 

Recently uploaded (20)

Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 

COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING

  • 1. COMPUTER CONCEPTS AND FUNDAMENTALS OF PROGRAMMING Ganesh B. Ingle, Vishwanath Mishra, Ms. G. Sridevi Devasena, Smt. Unnati Nitin Chaudhari, Wallace Jacob M A L AY S I AS I N G A P O R EI N D I A
  • 2. Notion Press Old No. 38, New No. 6 McNichols Road, Chetpet Chennai - 600 031 First Published by Notion Press 2018 Copyright © Ganesh B. Ingle, Vishwanath Mishra, G. Sridevi Devasena, Unnati Nitin Chaudhari, Wallace Jacob 2018 All Rights Reserved. ISBN 978-1-644291-23-8 This book has been published with all efforts taken to make the material error-free after the consent of the author. However, the author and the publisher do not assume and hereby disclaim any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from negligence, accident, or any other cause. No part of this book may be used, reproduced in any manner whatsoever without written permission from the author, except in the case of brief quotations embodied in critical articles and reviews.
  • 3. Preface We will remain indebted to the luminaries of the ilk of Wilhelm Schickard, Blaise Pascal, Guglielmo Marconi, Samuel F. B. Morse, Nikola Tesla, Charles Babbage, Lady Ada Lovelace, John von Neumann, Alan Turing, Grace Hopper, Edsger W. Dijkstra, Claude Shannon, Edgar F. Codd, Dennis Ritchie, Bjarne Stroustrup, Vint Cerf, Tim Berners-Lee, Sergey Brin, Larry Page, Steven Paul Jobs, and their like, who framed and changed the landscape of electronics, telecommunications and computing forever. We are also thankful to Vijay Mukhi (and his team), Yashvant Kanetkar whose books on BASIC, C, C++, UNIX, and JAVA, explored acres and acres of uncharted territory. We feel that their contribution cannot be measured. We have drawn inspiration from them and hence written this book. This book is a humble endeavor on our part to help the IMU Marine Engineering and Nautical Science students appreciate and comprehend the very important subject: Computer Science. Indubitably ‘computer science and technology’ has invaded and pervaded our lives and the best course of action would be to understand it and use it for the benefit of every living and non-living being. As frail human beings, we might be lacking in many spheres. However, we are open to constructive criticism and humbly solicit suggestions for improvement of the text from the esteemed readers of our book.
  • 4.
  • 5. CONTENT Chapter – 1 1 INTRODUCTION TO COMPUTER Chapter – 2 11 COMPUTER SOFTWARE Chapter – 3 18 INTRODUCTION Chapter – 4 24 DATA TYPES AND OPERATORS Chapter – 5 35 DECISION CONTROL INSTRUCTIONS Chapter – 6 46 DECISION MAKING AND LOOPING Chapter – 7 59 ARRAYS Chapter – 8 75 STRINGS Chapter – 9 79 USER DEFINED FUNCTIONS Chapter – 10 83 POINTERS Chapter – 11 89 STRUCTURES AND UNIONS Chapter – 12 148 ELECTRONIC COMMERCE
  • 6.
  • 7. Chapter – 1 INTRODUCTION TO COMPUTER 1.1  Computer Introduction It is an electronic device capable of performing complex arithmetical and logical operations to give desired output. 1.1.1  Characteristics of Computer are as follows: • Speed • Arithmetical and Logical Operations • Accuracy • Reliability • Storage • Retrieving Data and Program • Automation • Versatility (Flexible) • Consistency • Communications 1.1.2 Hardware/Software Computer Hardware Parts of computer, which can be touch is called hardware.(Physical Parts) • Monitor • CPU • Key Board • Mouse • Speaker Computer Software Parts of computer, which cannot be touch is called software. These are set of instructions or programs written in any computer programming language. Operating System Software: Windows, MAC, Linux Application Software: MS Office, Photoshop, Media Player Internet Browser Software: Internet Explorer, Google Chrome, Mozilla Firefox, etc.
  • 8. Computer Concepts and Fundamentals of Programming 2 1.1.3  Generations of computer i. First(1945-1955): Used vacuum tubes. Were very large. Generated immense heat. Very expensive. ii. Second(1955-1965):Used transistors. Continued to be large andexpensive. iii. Third(1965-1975):Used integrated circuits. Significant reduction in size and cost iv. Fourth(1975-1995): Uses Very Large Scale Integration. Desktop computers would not have been possible without VLSI. It used Microprocessor minimizing the size of P.C. v. Fifth: Will provide us with Artificial intelligence. Also called knowledge information processing system Fig: Generations of computer 1.2  Classification of Computers Computers are classified depending upon the types of electronics/hardware and processing power Depending on hardware they are classified in to • Analog, • Digital and • Hybrid Depending on processing power and speed they are classified in to Personal computer • A single-user computer • Can be useful at School, Home, etc. • Known as Micro Computer • Laptop, Desktop Workstation • A powerful, single-user computer. • A workstation is like a personal computer, but it has a more powerful microprocessor • higher-quality monitor. • Can be found in companies etc. Minicomputer • A multi-user computer • Capable of supporting from 10 to hundreds of users simultaneously. • Can be found in banks, government departments etc.
  • 9. Introduction to computer 3 Mainframe • A powerful multi-user computer • Capable of supporting hundreds or thousands of users simultaneously. Supercomputer • An extremely fast computer • Can perform hundreds of millions of instructions per second • Weather, scientific research can be done by these types of computer 1.3  Basic internet terminology Host A computer that is used to transfer data on the Internet. Web Hosting To store and make web pages available and ready for inquiries, or a computer that has a consistent connection to the Internet. Domain A domain name is a description or representation of a computer's location on the Internet. It is usually separated by a dot. For example: http://www.imu.edu.in DNS DNS (Domain Name System) is a large database of domain names and their correspondent Internet (IP Addresses). IP address This 32 bit address mechanism for addressing the devices on the network. Different classes of IP address as per the IPV4 standard are as follows: i. Class A –(0-126) ii. Class B-(128-191) iii. Class C-(192-223) iv. Class D-(224-239) v. Class E-(240-255) The 127 is used by the local host as loop back adapter and for the inter processes communication. In the above list class D and E are used for the experimental purpose. HTML Hypertext Markup Language is a coding language used to tell a browser how to place pictures, text, multimedia and links to create a web page. FTP File Transfer Protocal is a method of transferring files between two computers on the Internet InterNic InterNic is governs and maintains the name and host registration on the Internet.
  • 10. Computer Concepts and Fundamentals of Programming 4 URL Uniform Resource Locator is a web address used to connect website on the World Wide Web. For example: http://www.imu.edu.in Port The total nober of ports are 0-65535.A a Port is a channel that a server software would listen to, for any inquiries. Bit Bit is a single digit base 2. For example: 1 is a bit or 0 is a bit. Byte A Byte generally consists of eight bits. Server The server computer coupled with server software, listens for inquiries from a client computer. Upload To upload is to transfer data from your computer to another computer. Download To download is to transfer data from another computer to your computer. sss 1.4  Basic computer organization Following points are important points as far as computer organization is concern Fig: CPU and main memory • Processor system and its operations: Data Movement Operations. It is moving data from memory to the CPU It is moving data from memory to memory. It performs all input and output. Arithmetic and Logical Operations. It performs all integer arithmetic. It compares two quantities shifting, rotating bits in a quantity, testing, comparing, and converting bits • CPU: manages the instruction-execution cycle. FETCH – DECODE – EXECUTE. Coordinates the activities of other devices. Different types of CPU operations are, starting a program Halting a program, skipping to other instructions, testing data to decide whether to skip over some instructions.
  • 11. Introduction to computer 5 Fig: inside CPU • Memory: (fast access) storage device for preserving binary data and instructions. Memory is divided into units or words. Each is usually a standard size or fixed-length. Each memory word has a unique address for random access. It has two types RAM and ROM. Random Access Memory (RAM). It is readable, writeable, usually volatile (e.g., Dynamic RAM or DRAM) used as general storage. ROM is Read Only Memory (ROM).It is readable, permanent, nonvolatile,Special-purpose storage for data and instructions. • Input/output system • Input/output devices • Secondary storage i. Main memory is organization ii. Types of instructions for a typical processor iii. Scale and performance factors 1.5  Number systems The “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. There are different types of number systems depending upon the base or radix. There are different types of number systems are as follows: • Binary (radix=2): 1000111101 (radix = 2) • Ternary (radix=3): 0 to 3 • Octal (radix=8): 0 to 7 • Decimal (radix=10): 0 to 9 • Hexadecimal (radix=16): 0 to 9 and A, B, C, D, E, F • BCD, EBCD, Excess3, BCO(Binary Coded Octal), BCH(Binary Coded Hexadecimal) • Binary, octal, decimal and hexadecimal are called positional number system
  • 12. Computer Concepts and Fundamentals of Programming 6 1.5.1  Decimal to binary conversion: 1) (37)10 = (100101)2 q r 2 37 1 2 18 0 2 9 1 2 4 0 2 2 0 2 1 1 2 0 2) (41.68755)10 = (101001.1011)2 q r 2 41 1 2 20 0 2 10 0 2 5 1 2 2 0 2 1 1 2 0 Note: conversion from radix 10 to any base –r system similar to the above example only 2 will replaced by r 1.5.2  Decimal to Octal Conversion (153.153)10 = (231.406517)8 q r 8 19 1 8 2 3 8 0 2 1.5.3  Decimal to Hexadecimal Conversion (253)10 = (FD)16 q r 16 253 13(D) 16 15 15(F) 100101 101001 0.68755 × 2 = 1.3750 0.3750 × 2 = 0.7500 0.7500 × 2 = 1.5000 101 231 0.153 × 8 = 4.104 0.104 × 8 = 0.832 0.832 × 8 = 6.656 0.656 × 8 = 5.248 0.248 × 8 = 1.984 0.984 × 8 = 7.872 0.406517 FD
  • 13. Introduction to computer 7 1.5.4  Binary to Decimal Conversion (101101)2 = 25 × 1+24 × 0 +23 × 1 + 22 × 1 + 21 × 1 + 20 × 1 (101101)2 = 32 + 8 + 4 + 1 = (45)10 1.5.5  Binary to Hexadecimal conversion (1100101001010010)2 = (CA52)16 i. First, split the binary number into groups of four digits, starting with the least significant digit. ii. Next, convert each group of four binary digits to a single hex digit. iii. Put the single hex digits together in the order in which they were found, and you’re done! 1100 1010 0101 00102 C A 5 2 1.5.6  Hexadecimal to Decimal Conversion A hexadecimal number can be converted into its equivalent number in decimal system by calculating the sum of the products of each symbol multiplied by its corresponding place value. Examples (6B39)16 = (27449)10 (6 × 163 ) + (11 × 162 ) + (3 × 161 ) + (9 × 160 ) = 24567 + 2816 +48 + 9 = 27449 1.5.7  Octal to Decimal conversion An octal number can be converted into its equivalent number in decimal system by calculating the sum of the products of each digit multiplied by its corresponding place value. (13256)8 = (5806)10 into its equivalent in decimal systems (1 × 84 ) + (3 × 83 )+(2 × 82 ) + (5 × 81 )+(6 × 80 ) = 4096 + 1536 + 128 + 40 + 6 = 5806 1.5.8  Octal to Hexadecimal conversion The given octal number can be converted into its equivalent hexadecimal number in two different steps: i. Convert the given octal number into its binary equivalent by representing each digit in the octal number to its equivalent 3-bit binary number. ii. Divide the binary number into 4-bit sections starting from the least significant bit Example: (365)8 = (F5)16 3 6 5 011 110 101 0000 1111 0101 0 F 5 } } } }
  • 14. Computer Concepts and Fundamentals of Programming 8 1.5.9  Binary coded decimal The BCD system is employed by computer systems to encode the decimal number into its equivalent binary number. This is generally accomplished by encoding each digit of the decimal number into its equivalent binary sequence. The main advantage of BCD system is that it is a fast and efficient system to convert the decimal numbers into binary numbers as compared to the pure binary system. The 4-bit BCD system is usually employed by the computer systems to represent and process numerical data only. In the 4-bit BCD system, each digit of the decimal number is encoded to its corresponding 4-bit binary sequence. The two most popular 4-bit BCD systems are: • Weighted 4-bit BCD code • Excess-3 (XS-3) BCD code 1.5.10 EBCDIC The EBCDIC code is an 8-bit alphanumeric code that was developed by IBM to represent alphabets, decimal digits and special characters, including control characters. The EBCDIC codes are generally the decimal and the hexadecimal representation of different characters. This code is rarely used by non IBM-compatible computer systems. 1.5.11  ASCII code The ASCII code is pronounced as ASKEE and is used for the same purpose for which the EBCDIC code is used. However, this code is more popular than EBCDIC code as unlike the EBCDIC code this code can be implemented by most of the non-IBM computer systems. Initially, this code was developed as a 7-bit BCD code to handle 128 characters but later it was modified to an 8-bit code. 1.5.12  Gray Code Gray code is another important code that is also used to convert the decimal number into 8-bit binary sequence. However, this conversion is carried in a manner that the contiguous digits of the decimal number differ from each other by one bit only. Decimal Number 8-Bit Gray Code 0 00000000 1 00000001 2 00000011 3 00000010 4 00000110 5 00000111 6 00001111 7 00001011 8 00001001 9 00001101 We can convert the Gray coded number to its binary equivalent by remembering the following two major rules: • The Most Significant Bit (MSB) of the Gray coded number and the equivalent binary number is always the same. • The next-to-most significant bit of the binary number can be determined by adding the MSB of the binary number to the next-to-most significant bit of the gray coded number.
  • 15. Introduction to computer 9 1.5.12  1! and 2 ! Complement Fixed point representation and floating point representation +ve numbers are stored in register of digital computer in sign magnitude form Negative numbers are stored in three different way a. Signed magnitude representation b. Signed 1s complement representation c. Signed 2s complement representation Why do we require 1! and 2! Complement? One’s complement and two’s complement are two important binary concepts. Two’s complement is especially important because it allows us to represent signed numbers in binary, and one’s complement is the interim step to finding the two’s complement.Two’s complement also provides an easier way to subtract numbers. Example (9)10 to binary is (0 0001001)2 Note: here MSB 0 indicate + sign (-9)10 to binary is a. 1 0001001 signed magnitude b. 1 1110110 signed 1s complement c. 1 1110111 signed 2s complement Note: 2s complement can be formed by leaving LSB unchanged and remaining taking 1s complement 1.5.13  Rules for binary addition and subtraction a. Addition b. Subtraction 0 + 0 = 0 0 - 0 = 0 0 + 1 = 1 0 - 1 = 1 borrow 1 1 + 0 = 1 1 - 0 = 1 1 + 1 = 1 carry 0 1 - 1 = 0 Example 1. Addition 2. Subtraction 1 0 1 1 0 1 (Augend) 1 0 1 1 0 1 (Minuend) 1 0 0 1 1 1 (Addend) 1 0 0 1 1 1 (Subtracted) 1 1 1 1 1 0 1 0 1 0 0 0 0 0 1 1 0 Sum = 1010100 Difference=1010100 1.5.14  Binary Multiplication The multiplication of two binary numbers can be carried out in the same manner as the decimal multiplication. Unlike decimal multiplication, only two values are generated as the outcome of multiplying the multiplication bit by 0 or 1 in the binary multiplication. These values are either 0 or 1.
  • 16. Computer Concepts and Fundamentals of Programming 10 The binary multiplication can also be considered as repeated binary addition. Therefore, the binary multiplication is performed in conjunction with the binary addition operation. A B A×B 0 0 0 0 1 0 1 0 0 1 1 1 1 1 0 0 1 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 1 1 1 1 0 0 0 1.5.15  Binary Division Binary division is also performed in the same way as we perform decimal division. Like decimal division, we also need to follow the binary subtraction rules while performing the binary division. The dividend involved in binary division should be greater than the divisor. The following are the two important points, which need to be remembered while performing the binary division. If the remainder obtained by the division process is greater than or equal to the divisor, put 1 in the quotient and perform the binary subtraction. If the remainder obtained by the division process is less than the divisor, put 0 in the quotient and append the next most significant digit from the dividend to the remainder. Example Perform the binary division of the decimal numbers 18 and 8. The equivalent binary representation of the decimal number 18 is 10010. The equivalent binary representation of the decimal number 8 is 1000. 1.2.16  Floating point representation 1 0 0 0 ) 1 0 0 1 0 ( 1 0 → Quotient 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 → Remainder Floating-point numbers are the numbers containing two different parts, integer part and fractional part. The floating-point numbers are also referred as real numbers. A notation known as scientific notation is used to represent the real numbers in the computer system. The scientific notation, also called exponential notation, represents the real numbers in the following form: 325.123 → 3.25123 × 102 0.000000245 → 2.45 × 10-7 1000.0101 → 1.0000101 × 23 4333.123 4.333123 × 103 43.33123 × 102 433.3123 × 101
  • 17. CHAPTER – 2 COMPUTER SOFTWARE 2.1  Computer software Computer software is software programs, applications, scripts, code written in any computer language which can be executed and instruction. In order to access hardware directly it requires software. In other word various kinds of programs used to operate computers and related devices can be also termed as software. 2.2  Types of software i. System software a. Operating system Operating system is an interface between the hardware and the user. b. System utility ii. Application software a. Word processing b. Spread sheets c. Database d. Web browser 2.3  Compter networking 2.3.1  Types of computer networks i. LAN • This is a local area network up to 100 meters with speed of 100 Mbps to 1000 Mbps • Any computer network for business, school, and college is termed as local area network. • LAN can bet connected to other LAN by means of bridges • Multiple LAN connected forms a WAN • On LAN users can share expensive devices, such as laser printers, as well as data.  • It works much faster as compared to traditional telephone network • Topology, Protocol and media distinguishes one LAN from another • Number of devices are connected by means of switch, or stack of switches, using a private addressing scheme. • The media generally used for LAN is twisted pair cables or coaxial cables • Less congestion in the network
  • 18. Computer Concepts and Fundamentals of Programming 12 ii. MAN • This A metropolitan area network. It is larger than LAN or group of LAN • A network up to a city, big university, telephone company network is termed as MAN • It interconnect several local area networks by bridging them with backbone lines • Less fault tolerance and more congestion in the network • It is costlier than Lan for implementation • Devices used are Modem ,Wire/Cable, repeaters • It’s hard to design and maintain a Metropolitan Area Network. • Data transfer rate and the propagation delay is moderate iii. WAN • This a wide area network • Data speed is lower 1/10 th of LAN • Propagation delay is one of the biggest problems • It has two types asynchronous transfer mode (ATM) network and Point-to-Point WAN • Devices used in WAN are Optic wires, Microwaves and Satellites.  • Communication medium used is PSTN or Satellite Link. • More noise and error in data transmission There are other types of networks other than this are as follows i. PAN (Personal Area Network) ii. SAN (Storage Area Network) iii. EPN (Enterprise Private Network) iv. VPN (Virtual Private Network) 2.3.2 Topology Method of arranging and connecting different computer on the network with different way is termed as topology. There are different topologies as follows: Fig: 5.1
  • 19. Computer software 13 i. BUS topology • All computers are connected by means of single backbone cable • Terminators are used to avoid the bouncing of the signals • There is no dedicated client server architecture existing in this topology • All computers are connected by means of T connectors to the backbone cable • Failure of backbone cable bring down the complete network ii. STAR topology • All computers are connected in star fashion by means of switch • Message is being broadcasted • Wastage of bandwidth • Failure of centralize switch bring down the complete network • Switch/hub can act as repeater or signal booster. • Unshielded Twisted Pair (UTP) Ethernet cable is used to connect computers. • Failure of one node does not affect the network • Performance such topology is depended on capacity of central device iii. RING topology • All the devices are connected to each other in the shape of a ring or a loop. • It connects all nodes and forms a closed loop. • Here new term token is used • Computer wants to pass a message, then it catches the token, attaches a message, and then transmits around the network. When its transmission is complete, the device passes the token to the next. • It much secure way of communication • Moving, adding and changing devices may affect the network • No need for network server to control the connectivity • A dual ring topology can be used as a backup if the first ring fails. • Slower than a star topology. iv. MESH topology • It has two types full mesh and partial mesh topology • In full mesh topology every node is connected with rest of the node • It is very expensive topology.it will need a lot of capital to invest • A broken node won’t distract the transmission of data in a mesh network. • It has huge bandwidth • It makes large data center • Maintaining mesh networks can be very hard to manage. • Network redundancy problem v. TREE topology • Its combination of BUS and Star topology • It is highly scalable topology • Identifying the faulty is easy • Best for implementation of temporary networks.
  • 20. Computer Concepts and Fundamentals of Programming 14 • Point to point connection for every devices • If one device is damaged it doesn’t affect the network • Failure of backbone cable bring down the complete network • This network is insecure, anybody can see transmitted data. • As more and more nodes maintenance becomes difficult vi. CELLULAR topology • This topology is mainly used for mobile communication. • It forms cellular structure and any authentic mobile device comes in vicinity of the network gets connected with the network. • Every cell represents cell represents a portion of the total network area. • In this topology every node transmits in a certain area called a cell. • Data transmission is in the form of cellular digital packet data. 2.3.3  Computer network devices i. HUB • Hub is generally used in LAN. • There are two types of hub active (with external power supply) and passive(without external power supply). • It handles a data types like frames then transmits to the destination port • Hub broadcasts the data • Hubs are stupid devices as they cannot distinguish between data ,which port a frame should be sent to • Passive hub don’t amplify the signals • Hubs works in data link layer of OSI reference model. ii. Switch • Switches is generally used in LAN. • Switches works in data link layer of OSI reference model. • It handles a data types like frames then transmits to the destination port • It filters the packets and regenerating forwarded packets. • It reduces the collision rate. • Many switches are self-learning. • Switches may have different port with different speed of transmission. • Almost one-half of the nodes connected to a switch can send data at the simultaneously. iii. Router • It works in the network layer of OSI reference model • It filter out network traffic • It dividing networks logically instead of physically. • Ip router divides network into many segments • It routs the packet to the particular network • There are two types of router static and dynamic • For every packet it calculate checksum, and rewrite the MAC header
  • 21. Computer software 15 iv. Bridge • It connects two or more LAN networks • It works in data link layer of OSI reference model • It segment’s the larger network • It has the capacity to block the incoming flow of data. • It can build a list of the MAC addresses • The types of bridges are Transparent Bridge, Source Route Bridge, Translational Bridge v. Gateway • It is a stopping point for data from other networks • This is a specialized computer.It also operates as a firewall and a proxy server. • It controls all of the data traffic your Internet Service Provider (ISP) • It keeps out unwanted traffic to get in private network. • Network interface cards (NIC/LAN card) • This is also called as LAN card, Ethernet card ,interface controller card, expansion card, network card, network adapter or network adapter card (NAC) • This is working in the physical layer of OSI reference model • It has RJ45 port through which it gets connected to network 2.3.4  OSI reference model Fig: OSI reference model
  • 22. Computer Concepts and Fundamentals of Programming 16 2.3.5 TCP/IP TCP/IP is normally considered to be a 4 layer system. The 4 layers are as follows: i. Application layer ii. Transport layer iii. Network layer iv. Data link layer Application layer This layer includes applications or processes that use transport layer protocols to deliver the data to destination computers. The list of application layer protocols are: i. HTTP (Hypertext transfer protocol) ii. FTP (File transfer protocol) iii. SMTP (Simple mail transfer protocol) iv. SNMP (Simple network management protocol) etc. Transport layer: This is a backbone to data flow between two hosts. This layer receives data from the application layer above it. There are many protocols that work at this layer but the two most commonly used protocols at transport layer are TCP and UDP. Network layer: The main purpose of this layer is to organize or handle the movement of data on network. The main protocol used at this layer is IP. While ICMP (used by popular ‘ping’ command) and IGMP are also used at this layer. Data link layer: This layer mainly consists of device drivers in the OS and the network interface card attached to the system. Both the device drivers and the network interface card take care of the communication details with the media being used to transfer the data over the network. Fig: TCP/IP layered model 2.3.6 Firewall A firewall is a protective barrier between your PC and internet. When you are connected to the Internet, you are a potential target to of cyber threats, such as hackers that attack through security loopholes. Types of firewall are as follows Hardware: A hardware firewall can be a router or any other security product that is placed between your PC and the outside world. More than one PC can be connected with that security device or router, and each will be protected by the firewall.
  • 23. Computer software 17 Software: A software firewall is installed on your PC, it will deflect incoming attacks and hide open ports. It will warn you about suspicious outgoing traffic. You can have a software firewall on each computer for strong protection. By installing software firewall, an attacker will have to cross two level security to access your PC. Fig: Firewall 2.3.7  IP and classes of IP(IPV4) This 32 bit address mechanism for addressing the devices on the network. Different classes of IP address as per the IPV4 standard are as follows: v. Class A –(0-126) vi. Class B-(128-191) vii. Class C-(192-223) viii. Class D-(224-239) ix. Class E-(240-255) The 127 is used by the local host as loop back adapter and for the inter processes communication. In the above list class D and E are used for the experimental purpose.
  • 24. CHAPTER – 3 INTRODUCTION 3.1  Origin of C language ‘C’ is a multi-purpose language (including system programming) whose development is linked to UNIX operating system. Many of the features of ‘C’ language stem from BCPL (developed by Martin Richards) and B (developed by Ken Thompson). Both BCPL and B are “type less” languages while C provides a variety of data types. It may not be an exaggeration to say that 'C' programming language, developed by Dennis Ritchie, circa 1969-1973 (although quite a few book quote the year as 1972), is one of the most powerful, general-purpose programming languages which has also inspired many other languages. In 1978, Dennis Ritchie and Brian W. Kernighan published the seminal book The C Programming Language (the version of the language described in the book is known as KR C) which served as a language definition and a formal reference that helped in vast popularization of the 'C' language. In 1983, ANSI instituted the X3J11 committee which was assigned a goal of developing a 'C' standard. The X3J11 committee produced its report by the end of 1989 – ANSI X3.159- 1989 “Programming Language C”. This version of 'C' is known as C89. This standard was ratified by ISO as ISO/IEC 9899-1990 (sometimes referred to as C90). In fact, C89 and C90 refer to the same language. In 1995, ISO released an extension to the internationalization support to the standard. This version is known as C95. A revised standard was again released in 1999 (now known as C99). In 2007, work began on yet another revision of the C standard resulting in the development of the C11 standard which was approved in December 2011. C89 contains 32 keywords which are given below: auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while C99 has 37 keywords. The five new keywords which were added are: _Bool, _Complex, _Imaginary, inline, restrict C11 has 44 keywords. The seven new keywords which have been added are: _Alignas, _Alignof, _Atomic, _Generic, _Noreturn, _Thread_local, _Static_assert Interestingly, 'C' language used to include a reserved keyword called entry, which in fact was never implemented and now has been removed as a reserved word.
  • 25. Introduction 19 3.2  Why C? 3.3  Structure of C program 3.3.1  Performing addition of two numbers with following constraint a) do not use –(-) operation b) do not use *(-1) operation c) do not use (a2-b2)/a-b operation #includestdio.h main() { int add ,diff, a,b; printf(nEnter the value of two numbersn ); scanf(%d%d,a,b); add = 2*a; diff = a - b; add=add-diff; printf(nThe addition of 2 nos without using + is:==%d ,add); } 3.3.2  The first function to be executed in a ‘C’ program: All 'C' programmers know that the main() function is the entry point for a 'C' program. Can a user-defined function be executed before the main() function in a 'C' program? Can a user-defined function be executed after the last statement in main() function in a 'C' program? Can the main() function be called explicitly from within another function? Can the return value from the main() function be utilised in a program? These questions often pose a serious challenge to a 'C' programmer. The program below (compiled using gcc) answers the aforementioned questions: /*The code below is explained in greater detail in Chapter 2*/ #includestdio.h void func1(void) __attribute__((constructor)); void func2(void) __attribute__((destructor)); main() { printf(nWithin main()); return -8; } void func1() { system(clear); printf(nWithin func1()); }
  • 26. Computer Concepts and Fundamentals of Programming 20 void func2() { int k = main(); printf(nWithin func2(), k = %d, k); } A sample output of the program is given below: Within func1() Within main() Within main() Within func2(), k = -8 The output of the above code testifies that func1() is called first, after which main() function is executed, after which func2() function is called, which in turn explicitly calls main() function which in turn returns -8 which is stored in integer variable k. [N.B. Two underscores precede the word attribute and two underscores follows the word attribute in the statements: void func1(void) __attribute__((constructor)); and void func2(void) __attribute__((destructor));] For those working on the TurboC compiler, the following program can be used: #includestdio.h void func1(); void func2(); #pragma startup func1 #pragma exit func2 main() { printf(nWithin main()); return -8; } void func1() { system(clear); printf(nWithin func1()); } void func2() { int k = main(); printf(nWithin func2(), k = %d, k); }
  • 27. Introduction 21 3.4.2  Executing a ‘C’ program using gcc Open an editor like gedit, kwrite Type the c program and save it with the extension .c if no error(s) then type the command: ./a.out Open terminal and type command gcc filename.c Compiling a 'C' program using gcc: exploring a few switches The gnu C compiler is widely used because of its versatility (it can carry out preprocessing, compilation, assembly and linking) and also it has set unmatched standards in terms of reliability. The gnu C compiler actually works in stages. The stages are as follows: the Source Code is converted into Translation Unit the Translation Unit is converted into Assembly Code the Assembly Code is converted into Object Code the Object Code is converted into an Executable File. As an instance, if a program is saved by the name test57.c, then on issuing the command: gcc test57.c the intermediate stages might be visualized as follows: test57.c → test57.i → test57.s → test57.o → a.out The following switches can be used with the gcc command line in order to examine the intermediate stages: gcc –E test57.c (in order to obtain the Translation Unit equivalent. In short the –E option tells gcc to stop compilation after preprocessing) gcc –S test57.c (in order to obtain the Assembly Code) gcc –c test57.c (in order to obtain the Object Code). gcc test57.c (in order to obtain the executable file a.out) [NOTE: The options –E and –S are in uppercase] Let us consider the code snippet (saved in a file test57.c, for instance) shown below: #includestdio.h main() { printf(Computer Science); return 0; }
  • 28. Computer Concepts and Fundamentals of Programming 22 In order to examine the intermediate assembly language file, the following commands can be used. $ gcc -S test57.c $ cat test57.s will produce the intermediate assembly language listing of the above code snippet. The command $ gcc -o test test57.c makes an executable file by the name of test. In order to look at the output now, the user can type the following command at the command line: $./test instead of typing./a.out. The GNU Compiler Collection (gcc) can compile programs written in several high level languages such as FORTRAN, C, C++, Java, Objective-C, etc. In order to determine languages whose programs can be compiled using gcc, the Package Manager rpm* can be used as illustrated below: $ rpm -qa | grep gcc A sample interaction with rpm (using it as suggested above) might appear as follows: compat-gcc-34-g77-3.4.6-4 gcc-4.1.2-14.el5 gcc-gfortran-4.1.1-52.el5 compat-gcc-34-c++-3.4.6-4 gcc-java-4.1.1-52.el5 compat-gcc-34-3.4.6-4 gcc-c++-4.1.1-52.el5 compat-libgcc-296-2.96-138 libgcc-4.1.2-14.el5 gcc-objc-4.1.1-52.el5 *rpm is a package manager which can be used to build, install, update, query and erase individual software packages. [N.B. gcc used to be the GNU 'C' Compiler, but is now used for GNU Compiler Collection.] In order to compile the program, the following instruction needs to be typed: gcc program-name.c -trigraphs To find out the version of gcc, one can use gcc -v The gdb utility in Linux gdb (GNU debugger) is an efficient utility for debugging a program that has been compiled by gcc (GNU compiler collection). In order to start gdb the user is only required to type gdb and press ENTER at the command line (although there are many alternatives of starting gdb). Let us understand using gdb through a sample program (Program listing one) Program listing one
  • 29. Introduction 23 #includestdio.h main() { double num1, num2, quot; printf(Enter the numerator: ); scanf(%lf, num1); printf(Enter the denominator: ); scanf(%lf, num2); quot=num1/num2; printf(n%lf/%lf=%lf, num1, num2, quot); return 0; } Suppose the above program is stored in a file by the name of test.c. In order to compile the program, the user may type: $ gcc -g test.c -o test It may not be meaningful to use gdb by compiling the program without the -g switch, since gdb will not have information related to variable names, function names, line numbers, etc. Once the program is compiled, the user can type $ gdb test Now, in order to run the program, the user can type run (or r) at the gdb prompt and press ENTER. [NOTE: The user can also type gdb -quiet test or gdb -q test in order to suppress the introductory and copyright messages which are displayed when gdb is invoked.] In order to list the program, the user can type list (or l) at the gdb prompt and press ENTER. In order to set a breakpoint at line number 10, the user can type b 10 at the gdb prompt and press ENTER. Function name can also be used for setting a breakpoint at the first executable statement within the function. After pausing at the indicated line, the user can type continue (or c) in order to continue executing the program. The breakpoint(s) can be deleted through the delete command. Once a breakpoint has been set, then the commands n (for next) and s (for step) can also be used to execute the next line of the program. The commands n and s work differently if the next line happens to be a function call. If n is used then the next pause will be at the statement following the function call, whereas, if s is used then the next pause will be at the first line of the function which is invoked. The bt command can be used for printing the current location within the program and the stack trace showing how the current location was reached if a function calls another function or itself i.e. there has been a series of function calls. The kill command can be used in order to terminate the program being executed in gdb. The help command can be typed at the gdb prompt if the user feels stuck anywhere. If the user wants to quit the gdb utility then the user should type q and press ENTER.
  • 30. CHAPTER – 4 DATA TYPES AND OPERATORS 4.1  Data Types Data (singular: datum, plural: data) are a collections of facts and figures. Data will be of particular type. For instance, 786 is an integer, 0.23 is a fractional value and ‘x’ is a letter of the English alphabet. The built-in data types in ‘C’ are as follows: Type Example Format specifier char char c = ‘a’; %c int int num = 786; %d, %i float float f = 0.3f %f, %e, %E, %g, %G double double d = 0.9876 %lf void Used with functions and pointers. It is wrong to write void a. Format specifiers are also known as conversion characters/format code. In ‘C’, a string is an array of characters terminated by the NULL character ‘0’ – backslash zero. The format specifier for string is %s. Use of Format specifiers %o and %x
  • 31. Data types and operators 25 Sample Program 4.1 /* for printing octal and hexadecimal equivalents of an integer */ #includestdio.h main() { int num = 9123; printf(nIn base 10, num = %d, num); printf(nIn base 8, num = %o, num); printf(nIn base 16, num = %x, num); return 0; } A sample output is shown below: In base 10, num = 9123 In base 8, num = 21643 In base 16, num = 23a3 Sample Program 4.2 /*When 0 (zero) and 0x precede an integer*/ #includestdio.h main() { int num1 = 03672; /* when an integer begins with 0, then it implies that it is an octal integer*/ int num2 = 0x3672; /* when an integer begins with 0x, then it implies that it is an hexadecimal integer*/ int num3 = 3672; printf(nnum1 = %d, num1); printf(nnum2 = %d, num2); printf(nnum3 = %d, num3); return 0; } A sample output is shown below: num1 = 1978 num2 = 13938 num3 = 3672 In C99, _Bool is also a data type. _Bool is a datatype for Boolean (true/false). The stdbool.h header files defines an alias bool for _Bool. Arrays, structures, enumerations are derived data types in ‘C’. ‘C’ language supports user-defined datatypes also. A variable declaration statement such as int n = 953; means four bytes will be given the name n and the integer 953 will be stored in these four bytes.
  • 32. Computer Concepts and Fundamentals of Programming 26 Escape sequences in ‘C’ An escape sequence in ‘C’ usually begins with the backslash () and is a sequence of two or more characters which when used inside a character or string literal is translated into another character or sequence of characters. Escape sequence Character represented a alarm i.e. a beep sound or a bell sound b backspace f formfeed n linefeed i.e. new line r carriage return t horizontal tab v vertical tab backslash ’ single quotation mark ” double quotation mark ? question mark printf(): A function for displaying output; scanf(): A function for accepting input. Obtaining an integer as input from the user: Sample Program 4.3 #includestdio.h main() { int num; printf(Enter an integer: ); scanf(%d, num); printf(nThe integer you entered is: %d, num); return 0; }
  • 33. Data types and operators 27 A sample output is shown below: Enter an integer: 786 The integer you entered is: 786 Sample Program 4.4 Obtaining a fractional number as input from the user: #includestdio.h main() { float num; printf(Enter a fractional value: ); scanf(%f, num); printf(nThe fractional value you entered is: %f, num); return 0; } A sample output is shown below: Enter a fractional value: 0.34 The fractional value you entered is: 0.340000 The sizeof() operator [sizeof() is an unary operator] in C can be used to determine the size (in bytes) of a variable, constant or datatype. Sample Program 4.5 #includestdio.h main() { printf(nsizeof(0.93) = %d, sizeof(0.93)); printf(nsizeof(0.93f) = %d, sizeof(0.93f)); printf(nsizeof(71) = %d, sizeof(71)); printf(nsizeof(71L) = %d, sizeof(71L)); /*lowercase L can also be used*/ return 0; } Obtaining a string as input from the user: Sample Program 4.6 #includestdio.h main() { char name[80]; printf(Enter your name: ); scanf(%s, name); printf(nThe name you entered is: %s, name); return 0; }
  • 34. Computer Concepts and Fundamentals of Programming 28 Enter your name: Ganesh Ingle The name you entered is: Ganesh When reading a string through scanf(%s, name); The scanf() stops reading after the first whitespace (tab, space or Enter). Therefore Ingle was not stored in name. In order to read blank spaces into a string variable, the scanf() function can be used as illustrated below: Sample Program 4.7 #includestdio.h main() { char name[81]; printf(nEnter your name: ); scanf(%[^n]s, name); /* whatever you type before pressing the ENTER key will be stored in name*/ printf(nYou entered: %s, name); return 0; } Enter your name:Ganesh Ingle You entered: Ganesh Ingle Sample program 4.8 /* Program illustrating the use of sizeof() operator */ #includestdio.h main() { printf(nsizeof(char) = %d, sizeof(char)); printf(nsizeof(int) = %d, sizeof(int)); printf(nsizeof(float) = %d, sizeof(float)); printf(nsizeof(double) = %d, sizeof(double)); printf(nsizeof(long int) = %d, sizeof(long int)); return 0; } sizeof(char) = 1 sizeof(int) = 4 sizeof(float) = 4 sizeof(double) = 8 sizeof(long int) = 4 sample program 4.9: The program below exemplifies the use of long long in 'C' langauage. Program listing #includestdio.h main() { long long n=1; /* The range of long long is from –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 */ int i;
  • 35. Data types and operators 29 system(clear); for(i=1;i11;i++) { printf(n%lld,n*n); n=n*10+1; } return 0; } Sample program 4.10. To print the message I am the one without using any semicolon through out the program #includestdio.h main() { if(printf(I am the one)) { } } 4.11 The program to print message without using {,} in the program using di graph. #includestdio.h main() % printf(nhello welcome to TMIn); printf(nGMn); printf(nnCompletedn); % Sample program 4.12The program to print message without using {,} in the program using tri-graph characters. #includestdio.h main() ?? printf(nhello welcome to TMIn); printf(nGMn); printf(nnCompletedn); ?? 4.2  Data models The choices made by each implementation about the sizes of the fundamental types are collectively known as data model. Four data models found wide acceptance: 32 bit systems: • LP32 or 2/4/4 (int is 16-bit, long and pointer are 32-bit) • Win16 API
  • 36. Computer Concepts and Fundamentals of Programming 30 • ILP32 or 4/4/4 (int, long, and pointer are 32-bit); • Win32 API • Unix and Unix-like systems (Linux, Mac OS X) 64 bit systems: • LLP64 or 4/4/8 (int and long are 32-bit, pointer is 64-bit) • Win64 API • LP64 or 4/8/8 (int is 32-bit, long and pointer are 64-bit) • Unix and Unix-like systems (Linux, Mac OS X) Other models are very rare. For example, ILP64 (8/8/8: int, long, and pointer are 64-bit) only appeared in some early 64-bit Unix systems (e.g. Unicos on Cray). 4.3 Constants Constants are of two types a. Numeric Constants • Integer Constants (eg. 1,-15, 045, 0X6) • Real Constants (eg.3.14) b. Character Constants • Single Character Constants(eg. ‘5’ ,’z’) • String Constants (eg. “IMU” • Backslash Character Constants Eg: Constants Meaning a beep sound b backspace f form feed n new line r carriage return t horizontal tab v vertical tab ' single quote double quote backslash 0 null
  • 37. Data types and operators 31 4.4 Operators 4.4.1  Arithmetic Operators Operator Description Example + Adds two operands. A + B = 30 − Subtracts second operand from the first. A − B = -10 * Multiplies both operands. A * B = 200 / Divides numerator by de-numerator. B / A = 2 % Modulus Operator and remainder of after an integer division. B % A = 0 ++ Increment operator increases the integer value by one. A++ = 11 -- Decrement operator decreases the integer value by one. A-- = 9 4.4.2  Relational Operators Operator Description Example == Checks if the values of two operands are equal or not. If yes, then the condition becomes true. (A == B) is not true. != Checks if the values of two operands are equal or not. If the values are not equal, then the condition becomes true. (A != B) is true. Checks if the value of left operand is greater than the value of right operand. If yes, then the condition becomes true. (A B) is not true. Checks if the value of left operand is less than the value of right operand. If yes, then the condition becomes true. (A B) is true. = Checks if the value of left operand is greater than or equal to the value of right operand. If yes, then the condition becomes true. (A = B) is not true. = Checks if the value of left operand is less than or equal to the value of right operand. If yes, then the condition becomes true. (A = B) is true. 4.4.3  Logical Operators Operator Description Example Called Logical AND operator. If both the operands are non-zero, then the condition becomes true. (A B) is false. || Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true. (A || B) is true. ! Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false. !(A B) is true. Sample Program 4.13 /*illustration of postfix and prefix */ #includestdio.h main() { int num1 = 7; int num2, num3; num2 = num1++; /*first assign the value of num1 (7 in this case) to num2 and thereafter increment the value of num1*/ printf(nnum1 = %d, num1); printf(nnum2 = %d, num2); num3 = ++num1; /*first increment the value of num1, and then assign the value of num1 to num3*/ printf(nnum1 = %d, num1);
  • 38. Computer Concepts and Fundamentals of Programming 32 printf(nnum3 = %d, num3); return 0; } A sample output is shown below: num1 = 8 num2 = 7 num1 = 9 num3 = 9 Sample program 4.14 /* to find the angle between the hour hand and the minute hand*/ #includemath.h #includestdio.h main() { int h, m; double a1, a2; system(clear); printf(nthis code determines the angle between the hour hand and the minute hand); printf(Enter time (h m): ); scanf(%d %d, h, m); a1 = fabs(((h * 30) + (m * 1/2.0)) - (m * 6)); a2 = 360 - a1; printf(nTime = %d:%d, h,m); printf(nAngle between the hour hand and minute hand: %lf %lf, a1,a2); printf(nnCompletedn); return 0; } 4.4.4  Ternary operator Conditional operators return one value if condition is true and returns another value is condition is false.This operator is also called as ternary operator. Syntax: (Condition? true_value: false_value); Example: (A 100? 0: 1); 4.4.5  Bitwise Operator p q p q p | q p ^ q 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1
  • 39. Data types and operators 33 Operator Description Example Binary AND Operator copies a bit to the result if it exists in both operands. (A B) = 12, i.e., 0000 1100 | Binary OR Operator copies a bit if it exists in either operand. (A | B) = 61, i.e., 0011 1101 ^ Binary XOR Operator copies the bit if it is set in one operand but not both. (A ^ B) = 49, i.e., 0011 0001 ~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. (~A ) = -61, i.e,. 1100 0011 in 2's complement form. Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. A 2 = 240 i.e., 1111 0000 Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. A 2 = 15 i.e., 0000 1111 4.4.6  Assignment operator Operator Description Example Binary AND Operator copies a bit to the result if it exists in both operands. (A B) = 12, i.e., 0000 1100 | Binary OR Operator copies a bit if it exists in either operand. (A | B) = 61, i.e., 0011 1101 ^ Binary XOR Operator copies the bit if it is set in one operand but not both. (A ^ B) = 49, i.e., 0011 0001 ~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. (~A ) = -61, i.e,. 1100 0011 in 2's complement form. Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. A 2 = 240 i.e., 1111 0000 Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. A 2 = 15 i.e., 0000 1111 4.4.7  Programs for practice Write a C program to solve following problems 1. To find the square of the number given by user. 2. To perform addition of two numbers entered by user. 3. To perform addition of two numbers without using + operator. 4. To calculate average of three real numbers entered by user. 5. To input a single character and display it with proper message. 6. To show the effect of various escape sequences. 7. To swap the values of two variables without using third variable. 8. To input the rainfall of three consecutive days in cms and find its a average. Print the output with proper messages. 9. Find the simple interest. Inputs are principal amount, period in year and rate of interest. 10. To enter a integer number and carry out modular division operation by 2,3 and 6 and display the result. 11. To find the average temperature of five sunny days. Assume the temperature in Celsius. 12. Find the area and perimeter of a) Square b) Rectangle c) triangle Accept the sides as input from user. 13. The speed of a van is 75 km/hr. Write a program to find the number of hours required for covering a distance of 500 km. 14. Write a program to evaluate the following expressions and display their results. 15. x2 + 2x3*(2*x) 16. (x+y+z)2 17. Write a program to read three integers from the keyboard using one scanf statement and output them on one line using: 18. Three printf statements, 19. Only one printf with conversion specifiers.
  • 40. Computer Concepts and Fundamentals of Programming 34 20. Calculate the volume and area of a sphere using the formulas: 21. V = 4µr3/3 22. A = 4µr2 23. test the program using the values for the radius. 24. WAP to Calculate the mass of air in an automobile tire, using the formula PV = 0.37m(T + 460)where P = pressure in pounds per square inch, V= volume in cubic feet, m=mass of air in pounds, T=temp. In Fahrenheit. The tire contains two cubic feet of air. Assume that the pressure is 32psi at room temperature.
  • 41. CHAPTER – 5 DECISION CONTROL INSTRUCTIONS The decision control instructions are broadly classified as: 1. if statement 2. if else statement 3. switch case statement 5.1  if statement if (test condition) { Statement 1; Statement 2; Statement 3; …………. …………. Statement n; } 5.2  if else statement if (test condition) { Statement 1; Statement 2; …………. …………. Statement n; } else { Statement 1; Statement 2; …………. …………. Statement n; }
  • 42. Computer Concepts and Fundamentals of Programming 36 5.3  nested if else statement if(condition) { //Nested if else inside the body of if if(condition2) { //Statements inside the body of nested if } else { //Statements inside the body of nested else } } else { //Statements inside the body of else } 5.4  if elseif else statement if (test condition) { Statement 1; Statement 2; …………. …………. Statement n; } else if { Statement 1; Statement 2; …………. …………. Statement n; } else { Statement 1; Statement 2; …………. …………. Statement n; }
  • 43. Decision control instructions 37 5.5  switch case statement The syntax of switch case construct is as follows Switch ( expression ) // this expression can int or char it should not be float or string { case value-1: block-1; break; case value-2: block-2; break; case value-3: block-3; break; case value-4: block-4; break; default: default-block; break; } 5.6  goto statement Generally goto is a unconditional jumping statement. It can be used as a loop statement as well. Beacusae of unconditional jumping it is not advised to use goto statement. Sample code that illustrates goto statement as follows #includestdio.h #includeconio.h void main() { int number; clrscr(); printf(“Mango”); goto x; // here x is a label not a variable of any type ,program jumps to the label x abruptly. y: printf(“Orange”); goto z; // here z is a label not a variable of any type ,program jumps to the label z abruptly. x: printf(“Banana”); goto y; // here y is a label not a variable of any type ,program jumps to the label z abruptly. z: printf(“Apple”); getch(); }
  • 44. Computer Concepts and Fundamentals of Programming 38 Sample Program 5.1 Write a program to check whether the entered year is a leap year or not considering century year condition (IMU question paper May June 2016) #include stdio.h #include conio.h int main() { int year; printf(Enter a year: ); scanf(%d,year); if(year%4 == 0) { if( year%100 == 0) { // year is divisible by 400, hence the year is a leap year if ( year%400 == 0) printf(%d is a leap year., year); else printf(%d is not a leap year., year); } else printf(%d is a leap year., year ); } else printf(%d is not a leap year., year); getch(); return 0; } Or Other logic #include stdio.h #include conio.h int main() { int year; printf(Enter a year: ); scanf(%d,year); if(year=1752) { if(year%4 == 0) printf(%d is a leap year., year ); else printf(%d is not a leap year., year ); } else {
  • 45. Decision control instructions 39 if( year%100 == 0 year%400 != 0) printf(%d is not a leap year., year); else if( year%100 == 0 year%400 != 0) printf(%d is a leap year., year); else if(year%4 == 0) printf(%d is a leap year., year ); else printf(%d is not a leap year., year ); } getch(); return 0; } Or other logic /** * C program to check Leap Year */ #include stdio.h main() { int year; /* Read year from user */ printf(Enter year: ); scanf(%d, year); /* * Check for leap year */ if(((year%4 == 0) (year%100 !=0)) || (year%400==0)) { printf(LEAP YEAR); } else { printf(COMMON YEAR); } } Sample Program 5.2 Write program to device a calculator with menu driven program # include stdio.h # include conio.h int main() { char operator; double firstNumber,secondNumber; printf(Enter an operator (+, -, *, /): );
  • 46. Computer Concepts and Fundamentals of Programming 40 scanf(%c, operator); printf(Enter two operands: ); scanf(%lf %lf,firstNumber, secondNumber); switch(operator) { case '+': printf(%.1lf + %.1lf = %.1lf,firstNumber, secondNumber, firstNumber+secondNumber); break; case '-': printf(%.1lf - %.1lf = %.1lf,firstNumber, secondNumber, firstNumber-secondNumber); break; case '*': printf(%.1lf * %.1lf = %.1lf,firstNumber, secondNumber, firstNumber*secondNumber); break; case '/': printf(%.1lf / %.1lf = %.1lf,firstNumber, secondNumber, firstNumber/firstNumber); break; // operator is doesn't match any case constant (+, -, *, /) default: printf(Error! operator is not correct); } getch(); return 0; } Sample program 5.3 Program to print three digit number in words #includestdio.h main() { int num, t, d1, d2, d3; system(clear); printf(This program is for printing a three digit integer in words: n); printf(Enter an integer: ); scanf(%d, num); if(num0) { t=-num; printf(minus ); } else if(num==0) { printf(zero); t=num; } else
  • 47. Decision control instructions 41 t=num; d1=t/100; d2=(t%100)/10; d3=t%10; if(d1==1) printf(One hundred ); else if(d1==2) printf(Two hundred ); else if(d1==3) printf(Three hundred ); else if(d1==4) printf(Four hundred ); else if(d1==5) printf(Five hundred ); else if(d1==6) printf(Six hundred ); else if(d1==7) printf(Seven hundred ); else if(d1==8) printf(Eight hundred ); else if(d1==9) printf(Nine hundred ); if(d2==1) { if(d3==1) printf(Eleven); else if(d3==2) printf(Twelve); else if(d3==3) printf(Thirteen); else if(d3==4) printf(Fourteen); else if(d3==5) printf(Fifteen); else if(d3==6) printf(Sixteen); else if(d3==7) printf(Seventeen); else if(d3==8) printf(Eighteen); else if(d3==9) printf(Nineteen); } else { if(d2==2) printf(Twenty );
  • 48. Computer Concepts and Fundamentals of Programming 42 else if(d2==3) printf(Thirty ); else if(d2==4) printf(Forty ); else if(d2==5) printf(Fifty ); else if(d2==6) printf(Sixty ); else if(d2==7) printf(Seventy ); else if(d2==8) printf(Eighty ); else if(d2==9) printf(Ninty ); } if(d2!=1) { if(d3==1) printf(One); else if(d3==2) printf(Two); else if(d3==3) printf(Three); else if(d3==4) printf(Four); else if(d3==5) printf(Five); else if(d3==6) printf(Six); else if(d3==7) printf(Seven); else if(d3==8) printf(Eight); else if(d3==9) printf(Nine); } printf(nnCompletedn); } Sample program 5.4 Write a program to Find the roots of quadratic equation using switch case construct /** * C program to find all roots of a quadratic equation using switch case */ #include stdio.h #include math.h //Used for sqrt() main() {
  • 49. Decision control instructions 43 float a, b, c; float root1, root2, imaginary; float discriminant; printf(Enter values of a, b, c of quadratic equation (aX^2 + bX + c): ); scanf(%f%f%f, a, b, c); discriminant = (b*b) - (4*a*c); /* * Computes roots of quadratic equation based on the nature of discriminant */ switch(discriminant 0) { case 1: //If discriminant is positive root1 = (-b + sqrt(discriminant)) / (2*a); root2 = (-b - sqrt(discriminant)) / (2*a); printf(Two distinct and real roots exists: %.2f and %.2fn, root1, root2); break; case 0: //If discriminant is not positive switch(discriminant 0) { case 1: //If discriminant is negative root1 = root2 = -b / (2*a); imaginary = sqrt(-discriminant) / (2*a); printf(Two distinct complex roots exists: %.2f + i%.2f and %.2f - i%.2fn, root1, imaginary, root2, imaginary); break; case 0: //If discriminant is zero root1 = root2 = -b / (2*a); printf(Two equal and real roots exists: %.2f and %.2fn, root1, root2); break; } } } Sample program 5.5 Write a program to count minimum number of notes in an amount /** * C program to count minimum number of notes in an amount */ #include stdio.h main() { int amount;
  • 50. Computer Concepts and Fundamentals of Programming 44 int note500, note100, note50, note20, note10, note5, note2, note1; note500 = note100 = note50 = note20 = note10 = note5 = note2 = note1 = 0 ; /* Reads amount from user */ printf(Enter amount: ); scanf(%d, amount); if(amount = 500) { note500 = amount/500; amount -= note500 * 500; } if(amount = 100) { note100 = amount/100; amount -= note100 * 100; } if(amount = 50) { note50 = amount/50; amount -= note50 * 50; } if(amount = 20) { note20 = amount/20; amount -= note20 * 20; } if(amount = 10) { note10 = amount/10; amount -= note10 * 10; } if(amount = 5) { note5 = amount/5; amount -= note5 * 5; } if(amount = 2) { note2 = amount /2; amount -= note2 * 2; } if(amount = 1) { note1 = amount; } printf(Total number of notes = n); printf(500 = %dn, note500); printf(100 = %dn, note100); printf(50 = %dn, note50);
  • 51. Decision control instructions 45 printf(20 = %dn, note20); printf(10 = %dn, note10); printf(5 = %dn, note5); printf(2 = %dn, note2); printf(1 = %dn, note1); } Sample program 5.6 Write a program to check given number is even or odd using switch case /** * C program to check Even or Odd number using switch case */ #include stdio.h main() { int num; /* * Reads a number from user */ printf(Enter any number to check even or odd: ); scanf(%d, num); switch(num % 2) { //If n%2 == 0 case 0: printf(Number is Even); break; //Else if n%2 != 0 case 1: printf(Number is Odd); break; } } 5.7  Programs for practice 1. WAP to find the roots of a quadratic equation by using if...else condition. 2. WAP to read six numbers and find the largest one by using ladder of if...else. 3. WAP to find the average of six subjects and display the results. 4. WAP to check whether the entered year is a leap year or not with all check points 5. WAP (a menu driven)to display the names of the days of a week. 6. WAP Read the values of a,b,c through keyboard. Add them and after addition check if it is in the range of 100 200 or not. Print separate message of each. 7. WAP to convert integer to character using if condition. 8. WAP to calculate the sum of the remainders obtained by dividing with modular division operations by 2 on 1 to 9 numbers.
  • 52. CHAPTER – 6 DECISION MAKING AND LOOPING 6.1  The for() loop The for() loop can be used for executing a statement/statements a specific (or infinite) number of times. The general form of the for() loop is as follows: for(expr1; expr2; expr3) { code block; } expr1 is executed only once when the for() loop is executed for the first time. expr2 is evaluated every time before entry into the loop till the time it does not evaluate to false. expr3 is evaluated every time except for the first time. The for() loop is an entry-controlled loop. Different constructs of for loop (these syntax are correct syntax) • for( ;condition;) { Increment / decrement; } • for(i=0,j=0,k=100; i=200;i++,j++,k++) { } • for(;i10;i++ ) { } • for(;i10;i++ ); { } [N.B.: These programs have been executed using Dev-C++ Version 5.11] #includestdio.h main() {
  • 53. Decision making and looping 47 /* printing the integers from 1 to 10 using a for() loop */ int i; for(i=1;i11;i++) { printf(ni = %d, i); } return 0; } 6.2  The while () loop: The general form of the while() loop is: while (expr) { code-block; } If the expr after while evaluates to true then the body of the while() loop will be executed, otherwise control is transferred to the statement following the while() loop body. The while() loop is an entry-controlled loop, which implies that if the expr evaluates to false right at the beginning then the body of the while loop will not be executed even once. #includestdio.h main() { /* printing the integers from 11 to 20 using a while() loop */ int j=11; while(j21)
  • 54. Computer Concepts and Fundamentals of Programming 48 { printf(nj = %d, j); j++; } return 0; } 6.3  The do... while() loop The general form of the while() loop is: do { code-block; }while (expr); If the expr after while evaluates to true then the body of the do... while() loop will be executed, otherwise control is transferred to the statement following the while() loop body. The body of the do... while(); loop will be necessarily executed at least once. The do... while() loop is an exit-controlled loop. #includestdio.h main() { /* printing the integers from 21 to 30 using a do...while() loop */ int k=21; do { printf(nk = %d, k); k++;
  • 55. Decision making and looping 49 }while(k=30); return 0; } 6.4  Difference between while and do while loop while do while It is entry controlled loop It is exit controlled loop The may not be executed if the condition is false to start with The loop will executed at least once while(condition) { Statement 1; Statement 2 ; Statement 3; } do { Statement 1; Statement 2 ; Statement 3; } while(condition); Sample program 6.1 Program to illustrate tribonacci series #includestdio.h int main() {int num,a=0,b=1,c=2,d=0,i; printf(nEnter the number:); scanf(%d,num); printf(%dt%dt%d,a,b,c); for(i=3;inum;i++) {
  • 56. Computer Concepts and Fundamentals of Programming 50 d=a+b+c; printf(t%d ,d); a=b; b=c; c=d; } } Sample program 6.2 Tetranacci series #includestdio.h int main() {int num,a=0,b=1,c=2,d=3,e=0,i; printf(nEnter the number:); scanf(%d,num); printf(%dt%dt%d,a,b,c); for(i=3;inum;i++) { e=a+b+c+d; printf(t%d ,e); a=b; b=c; c=d; d=e; } } Sample program 6.3 Lucas series #includestdio.h main() {  int x,y,z,num;  printf(Enter the limit of Lucas number: );  scanf(%d,num);  x=2;  y=1;  while(num=x)  {    printf( %d,x);    z=x+y;    x=y;    y=z;  }
  • 57. Decision making and looping 51 } Sample program 6.4 Palindrome number #includestdio.h void pal(); main() { pal(); } void pal() { int n,x,mod,rev=0; printf(nEnter No.); scanf(%d,n); x=n; while(n) { mod=n%10; rev=rev*10+mod; n=n/10; } if(rev==x) printf(n PAL n); else printf(n NOT PAL n); } Sample program 6.5 Special number #includestdio.h void sp(); main() { sp(); } void sp() { int n,x,mod,sum=0,f; printf(n Enter no.); scanf(%d,n); x=n; int i; while(n) { mod=n%10; f=1;
  • 58. Computer Concepts and Fundamentals of Programming 52 for(i=1;i=mod;i++) f=f*i; sum=sum+f; n=n/10; } if(sum==x) printf(n SPL); else printf(n NOT SPL); } Sample program 6.6 Write a program to check whether the number is n- Narcissistic number #includestdio.h main() { long int cube,n,mod,sum=0,temp; printf(Enter the any number: ); scanf(%d,n); cube=n*n*n; temp=cube; digit=0; while(cube) { mod=cube%10; digit++; cube=cube/10; } cube=x; while(cube) { mod=cube%10; sum=sum+pow(mod,digit); cube=cube/10; } if(sum==n) printf(“The given number: = %d is a n- Narcissistic number”,sum); else printf(“The given number: = %d is a n- Narcissistic not number”,sum); } Sample program 6.7 Armstrong number is also n- Narcissistic page #includestdio.h main() { int mod,n,x,arm1=0; printf(enter the val of n);
  • 59. Decision making and looping 53 scanf(%d,n); x=n; while(n) { mod=n%10; arm1=arm1+mod*mod*mod; n=n/10; } if(arm1==x) printf(nnyes armstrong hai!!!!!nn); else printf(nnyes armstrong nahi hai!!!!!nn); } Sample program 6.8 Write a program to check whether the number is Prime number or not #includestdio.h main() { int n, i = 3, count, c; printf(Enter the number of prime numbers requiredn); scanf(%d,n); if ( n = 1 ) { printf(First %d prime numbers are:n,n); printf(2n); } for ( count = 2 ; count = n ; ) { for ( c = 2 ; c = i - 1 ; c++ ) { if ( i%c == 0 ) break; } if ( c == i ) { printf(%dn,i); count++; } i++; } } Sample program 6.9 Write a program to check whether the entered number is a.Magic number or not //magic number 82=8+2=10=1+0=1
  • 60. Computer Concepts and Fundamentals of Programming 54 #includestdio.h main() { int n,x,mod,rev=0; printf(nEnter the limitn); scanf(%d,n); TMI: for(x=n;n;n=n/10) {mod=n%10;rev+=mod;} if(rev=10) {n=rev;rev=0; goto TMI; } else if(rev==1) printf(Entered number is a magic no ); else printf(Entered number is not a magic no ); } Sample program 6.10 Write a program to print the following Pattern /* * * * * * * * * * * * * * * * */ #includestdio.h main() { int n,i,j,k,l; printf(nEnter the limitn); scanf(%d,n); // work for the rows for(i=1;i=n;i++) { for(k=1;k=10000000;k++); for(l=40;l=i;l--)// work for the spaces {printf( );} for(j=1;j=i;j++) {printf( *);} printf(n); } }
  • 61. Decision making and looping 55 6.5  Programs for practice 1. WAP to find and print the sum of digits of a number entered by user. 2. WAP to find and print the greatest digit of a number entered by user. 3. WAP to find and print the smallest digit of a number entered by user. 4. WAP to find and print all even digits of a number entered by user. 5. WAP to Print the square root of each digit of any number. Consider each digit as perfect square. For example 494 the square roots to be printed should be 232. 6. WAP to enter two integer values through keyboard. Using while loop, perform the product of the two integers. In case product is zero, loop should be terminated otherwise loop will continue. 7. To enter integer number and find the largest and smallest digit of that number based on user choice. 8. To find and print the Fibonacci series till n where n is user defined. 9. To condense the number to a single digit. 10. To check whether the number entered by user is Arm-strong number or not. 11. To check whether the number entered by user is perfect number or not. 12. To check whether the number entered by user is magic number or not. 13. To check whether the number entered by user is palindrome number or not. 14. To check whether the number entered by user is special number or not. 15. To find and print the Factorial of a number entered by user. 16. Write a program in ‘C’ to generate the following output: (a). 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 (b). 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 (c). 5 4 3 2 1 5 4 3 2 5 4 3 5 4 (d). * ** ***
  • 62. Computer Concepts and Fundamentals of Programming 56 **** ***** **** *** ** * (e). C CO COM COMP COMPU COMPUT COMPUTE (f). C COO COOMMM COOMMMPPPP COOMMMPPPPUUUUU COOMMMPPPPUUUUUTTTTTT COOMMMPPPPUUUUUTTTTTTEEEEEEE (g). C CCO CCCOOM CCCCOOOMMP CCCCCOOOOMMMPPU CCCCCCOOOOOMMMMPPPUUT CCCCCCCOOOOOOMMMMMPPPPUUUTTE (h). C CCOO CCCOOOMMM CCCCOOOOMMMMPPPP CCCCCOOOOOMMMMMPPPPPUUUUU CCCCCCOOOOOOMMMMMMPPPPPPUUUUUUTTTTTT CCCCCCCOOOOOOOMMMMMMMPPPPPPPUUUUUUUTTTTTTTEEEEEEE
  • 63. Decision making and looping 57 (i). 1 121 12321 1234321 123454321 12345654321 1234567654321 (j). 9 989 98789 9876789 987656789 98765456789 9876543456789 987654323456789 98765432123456789 (k) 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 (l). 1 23 456 78910 (m). ( )( )() ()() ()()( (n). 1
  • 64. Computer Concepts and Fundamentals of Programming 58 232 34543 4567654 567898765 (o). 1 232 34543 4567654 567898765 67890109876 7890123210987 890123454321098
  • 65. CHAPTER – 7 ARRAYS 7.1 Arrays Suppose we want to obtain 10 integer values, perform mathematical or other operations on them and then print the results, then we might require ten integer variables: var1, var2, var3,... , var10, for instance. Several programming languages provide the concept of arrays which help in reducing the number of variables because of a common name and indices for referencing individual elements. Let us consider an example: #includestdio.h main() { int num[10]; int i; printf(nNow obtaining 10 integer values: n); for(i=0;i10;i++) { printf(Enter %dth integer: , i); scanf(%d, num[i]); } printf(nThe 10 integer values which you entered are as follows:); for(i=0;i10;i++) printf(nnum[%d] = %d, i, num[i]); return 0; }
  • 66. Computer Concepts and Fundamentals of Programming 60 A sample interaction with the program might appear as follows: How arrays are stored in memory? The declaration int num[10]; indicates to the ‘C’ compiler that memory is to be reserved (continuous locations) for storing 10 integer values. The locations are individually identified as num[0], num[1], num[2],... , num[9]. If an integer requires 4 bytes for storage, and if the first integer is being stored in locations identified as 2358932, 2358933, 2358934, 2358935; then the second integer would be stored in the locations: 2358936, 2358937, 2358938 and 2358939. In the diagram below, the numbers on the right indicate the address of the individual array elements. num[0] 2358932 num[1] 2358936 num[2] 2358940 num[3] 2358944 num[4] 2358948 num[5] 2358952 num[6] 2358956 num[7] 2358960 num[8] 2358964 num[9] 2358968 A few important points pertaining to arrays: If an array is declared as:
  • 67. Arrays 61 int num[10]; (i) then the first element of the array will be referred to as num[0] and the last element of the array will be referred to as num[9]; (ii) If an array is declared as a global array [above main() ], then (a) It will be initialized with NULL values in case it is a char type array (b) It will be initialized with 0 (zero) in case it is a numeric array (iii) If an array is declared as a static array, then (a) It will be initialized with NULL values in case it is a char type array (b) It will be initialized with 0 (zero) in case it is a numeric array (iv) If a numeric type array is partially initialized at the place where it is declared, then the rest of the elements are automatically set to zero. (v) An array name is a pointer to itself. Thus num[0] and num would be the same. Two-dimensional arrays A declaration such as: int num[4][5]; creates an array of 4 rows and 5 columns and might be visualized as follows: Col 0 Col 1 Col 2 Col 3 Col 4 Row 0 Row 1 Row 2 Row 3 The individual elements might be accessed as follows: num[0][0] num[0][1] num[0][2] num[0][3] num[0][4] num[1][0] num[1][1] num[1][2] num[1][3] num[1][4] num[2][0] num[2][1] num[2][2] num[2][3] num[2][4] num[3][0] num[3][1] num[3][2] num[3][3] num[3][4] The program below demonstrates how to enter values into a two-dimensional array and then print the values. #includestdio.h #define ROWS 3 #define COLS 4 main() { int mat[ROWS][COLS]; int i, j; printf(nNow obtaining integers for %d X %d matrix:n, ROWS, COLS); for(i=0;iROWS;i++)
  • 68. Computer Concepts and Fundamentals of Programming 62 { for(j=0;jCOLS;j++) { printf(Enter integer for %dth row and %dth column: ,i,j); scanf(%d, mat[i][j]); } } printf(nThe matrix is as follows:n); for(i=0;iROWS;i++) { for(j=0;jCOLS;j++) { printf(%8d, mat[i][j]); } printf(n); } printf(nThe addresses of the matrix elements are as follows:n); printf(nAddress (matrix element)n); for(i=0;iROWS;i++) { for(j=0;jCOLS;j++) { printf(%u (%d) , mat[i][j], mat[i][j]); } printf(n); } return 0; }
  • 69. Arrays 63 A sample output is shown below: Sample program 7.1 Program to illustrate matrix multiplication of two matrices of same order Matrix multiplication #include stdio.h main() { int m, n, p, q, c, d, k, sum = 0; int first[10][10], second[10][10], multiply[10][10]; printf(Enter the number of rows and columns of first matrixn); scanf(%d%d, m, n); printf(Enter the elements of first matrixn); for ( c = 0 ; c m ; c++ ) for ( d = 0 ; d n ; d++ ) scanf(%d, first[c][d]); printf(Enter the number of rows and columns of second matrixn); scanf(%d%d, p, q); if ( n != p ) printf(Matrices with entered orders can't be multiplied with each other.n); else { printf(Enter the elements of second matrixn); for ( c = 0 ; c p ; c++ )
  • 70. Computer Concepts and Fundamentals of Programming 64 for ( d = 0 ; d q ; d++ ) scanf(%d, second[c][d]); for ( c = 0 ; c m ; c++ ) { for ( d = 0 ; d q ; d++ ) { for ( k = 0 ; k p ; k++ ) { sum = sum + first[c][k]*second[k][d]; } multiply[c][d] = sum; sum = 0; } } printf(Product of entered matrices:-n); for ( c = 0 ; c m ; c++ ) { for ( d = 0 ; d q ; d++ ) printf(%dt, multiply[c][d]); printf(n); } } } Sample program 7.2 Write a first category function program to read a two matrices A and B of order 9x9 and print the following. a)A+B and b)A-B #includestdio.h main() { int a[3][3],b[3][3],c[3][3],i,j; printf(Enter the First 3x3 Matrix: ); for(i=0;i3;i++) { for(j=0;j3;j++) scanf(%d,a[i][j]); } printf(Enter the Second 3x3 Matrix: ); for(i=0;i3;i++) { for(j=0;j3;j++) scanf(%d,b[i][j]); } printf(nThe Sum of Matrices is: ); for(i=0;i3;i++)
  • 71. Arrays 65 { printf(n); for(j=0;j3;j++) { c[i][j]=a[i][j]+b[i][j]; printf(%d ,c[i][j]); } } printf(nnThe Difference of Matrices is: ); for(i=0;i3;i++) { printf(n); for(j=0;j3;j++) { c[i][j]=a[i][j]b[ i][j]; //2 mark printf(%d ,c[i][j]); } } } Sample program 7.3 Write a program that will put 8 queens on a Chessboard so that no queen can capture another. The size of the board is 8 x 8. One queen can capture another if it is standing in the same row (horizontal), or in the same column (vertical), or on the same diagonal as the other queen. #includestdio.h #includemath.h int a[30],count=0; int place(int pos) { int i; for(i=1;ipos;i++) { if((a[i]==a[pos])||((abs(a[i]a[pos])==abs(ipos)))) return 0; } return 1; } void print_sol(int n) { int i,j; count++; printf(nnSolution #%d:n,count);
  • 72. Computer Concepts and Fundamentals of Programming 66 for(i=1;i=n;i++) { for(j=1;j=n;j++) { if(a[i]==j) printf(Qt); else printf(*t); } printf(n); } } void queen(int n) //1 mark { int k=1; a[k]=0; while(k!=0) { a[k]=a[k]+1; while((a[k]=n)!place(k)) //1 mark a[k]++; if(a[k]=n) //1 mark { if(k==n) print_sol(n); else { k++; a[k]=0; //1 mark } } else k; } } main() //1 mark { int i,n; printf(Enter the number of Queensn); scanf(%d,n);
  • 73. Arrays 67 queen(n); printf(nTotal solutions=%d,count); } Selection Sort In Selection Sort, the element at the zeroth position is compared with all the elements below it and an interchange performed as and when required (depending on whether the elements have to be arranged in ascending or descending order). Thereafter, the element at the first position is compared with all the elements below it and an interchange performed as and when required. Similarly, the elements at the second, third,... position are compared with all the elements below them and an interchange performed as and when required. The program below is an implementation of Selection Sort: #includestdio.h #define SIZE 10 main() { int array[SIZE]; int i, j, t; printf(nNow obtaining %d integers: n, SIZE); for(i=0;iSIZE;i++) { printf(Enter %dth integer: , i); scanf(%d, array[i]); } printf(nnBefore sorting:); for(i=0;iSIZE;i++) printf(n%d, array[i]); for(i=0;iSIZE-1;i++) { for(j=i+1;jSIZE;j++) { if(array[i]array[j]) { t=array[i]; array[i]=array[j]; array[j]=t; } } } printf(nnAfter sorting:); for(i=0;iSIZE;i++) printf(n%d, array[i]); return 0; }
  • 74. Computer Concepts and Fundamentals of Programming 68 A sample output is shown below: Bubble sort In Bubble sort two successive elements are compared with each other and an interchange performed as and when required (depending on whether sorting is required in ascending or descending order). #includestdio.h #define SIZE 10 main() { int num[SIZE]; int i, j; int t; for(i=0;iSIZE;i++) {
  • 75. Arrays 69 printf(Enter %dth integer: , i); scanf(%d, num[i]); } printf(nBefore sorting: ); for(i=0;iSIZE;i++) printf(n%d, num[i]); for(i=0;iSIZE-1;i++) { for(j=0;jSIZE-1;j++) { if(num[j]num[j+1]) { t = num[j]; num[j]=num[j+1]; num[j+1]=t; } } } printf(nAfter sorting: ); for(i=0;iSIZE;i++) printf(n%d, num[i]); return 0; }
  • 76. Computer Concepts and Fundamentals of Programming 70 A sample output is shown below: Suppose the integers are entered in the following order: 9012 481 916 -9129 0 -873 3782 6712 -865 -2 After 0th run of the outer for(i...) loop 481 916 -9129
  • 77. Arrays 71 0 -873 3782 6712 -865 -2 9012 (The largest integer in the array is at the bottom of the array) After 1th run of the outer for(i...) loop 481 -9129 0 -873 916 3782 -865 -2 6712 (The second highest integer in the array is in the second last position in the array) 9012 After 2th run of the outer for(i...) loop -9129 0 -873 481 916 -865 -2 3782 (The third highest integer in the array is in the third last position in the array) 6712 9012 After 3th run of the outer for(i...) loop -9129 -873 0 481 -865 -2 916
  • 78. Computer Concepts and Fundamentals of Programming 72 3782 6712 9012 After 4th run of the outer for(i...) loop -9129 -873 0 -865 -2 481 916 3782 6712 9012 After 5th run of the outer for(i...) loop -9129 -873 -865 -2 0 481 916 3782 6712 9012 After 6th run of the outer for(i...) loop -9129 -873 -865 -2 0 481 916 3782 6712 9012 After 7th run of the outer for(i...) loop
  • 79. Arrays 73 -9129 -873 -865 -2 0 481 916 3782 6712 9012 After 8th run of the outer for(i...) loop -9129 -873 -865 -2 0 481 916 3782 6712 9012 After sorting: -9129 -873 -865 -2 0 481 916 3782 6712 9012 7.3  Programs for practice 1. To read 10 integers in an array and print all the values stored in the array. 2. To read 10 integers in an array and print all the values in reverse order stored in the array. 3. To read 10 integers in an array and Find the largest and smallest number from the array. 4. To read 10 fractions in an array and print alternate array elements.
  • 80. Computer Concepts and Fundamentals of Programming 74 5. To print all even numbers stored in an array of size n, where n is user defined. 6. To accept an array of n elements, n user defined. Increase each value by 100 and print the new array. 7. To read 10 integers in an array. Find and print the largest and smallest number. 8. To accept an array of n numbers. Check value, if an even number is found, increase its value by 10, if odd decrease its value by 5and print both odd as well as new array. 9. To find and print all arm-strong numbers stored in an array of size n, where n is user defined. 10. To find and print all prime numbers stored in an array of size n, where n is user defined. 11. To find sum and average of any n values stored in an array. 12. To accept any n value,store them in the array and check the presence of any number entered by user in the array. If present, print the number, its first location and how many times it occurs in the array. 13. To read a number containing five digits. Perform square of each digit. 14. To read a number of any length. Perform the addition and subtraction on largest and smallest digits of it
  • 81. CHAPTER – 8 STRINGS String functions in ‘C’ In ‘C’ language a string is an array of characters terminated by ‘0’ (the null character). Some of the most commonly used string functions in ‘C’ are: strcat(): for concatenating two strings, strchr(): used for locating the first occurrence of the character (second argument) in the string (first argument), strcmp(): used for comparing two strings, strcpy(): used for copying the string contained as the second argument to the function, in the first argument to the function, strncpy(): used for avoiding buffer overflow when copying, strlen(): for computing the length of the string, strncat(): for appending n bytes, strlwr(): for converting a string to lowercase strupr(): for converting a string to uppercase The programs below demonstrate the use of a few string functions. #includestdio.h #includestring.h main() { char str[80]; printf(nEnter any string:); scanf(%[^n], str); printf(nstr = %s, str); printf(nstrlwr(str) = %s, strlwr(str)); printf(nstrupr(str) = %s, strupr(str)); printf(nstrlen(str) = %d, strlen(str)); return 0; }
  • 82. Computer Concepts and Fundamentals of Programming 76 A sample output is shown below: #includestdio.h #includestring.h main() { char str1[] = Sky is the limit; char str2[] = Sky is Not the limit; char str3[80] = ; int result; printf(nnstr1 = %s, str1); printf(nnstr2 = %s, str2); printf(nnstr3 = %s, str3); strcpy(str3, str2); /*strcpy(destination, source)*/ printf(nnAfter copying str2 to str3, str3 = %s, str3); result = strcmp(str1, str2); /* strcmp(str1, str2) returns a value 0 if str1 alphabetically precedes str2, strcmp(str1, str2) returns a value 0 if str2 alphabetically precedes str1, strcmp(str1, str2) returns 0 if str1 is exactly the same as str2 */ printf(nnOn comparing str1 and str2, result = %d, result); return 0; }
  • 83. Strings 77 A sample output is shown below: const char* strstr(const char *str1, const char *str2); The strstr() function returns a pointer to the first occurrence of str2 in str1, or a null pointer if str2 is not a subset of str1. A program illustrating the use of strstr() follows: #includestdio.h #includestring.h main() { char str1[] = Sky is the limit; char *result; printf(nnstr1 = %s, str1); result= strstr(str1, the); printf(nnresult = %s, result); result= strstr(str1, star); printf(nnresult = %s, result); return 0; } A sample output is shown below: str1 = Sky is the limit result = the limit result = (null)
  • 84. Computer Concepts and Fundamentals of Programming 78 Sample program 8.1.Write a program to enter a paragraph and check number of alphabet, digit or special character /* C program to check alphabet, digit or special character */ #include stdio.h main() { char ch; /* Reads a character from user */ printf(Enter any character: ); scanf(%c, ch); /* Checks if it is an alphabet */ if((ch = 'a' ch = 'z') || (ch = 'A' ch = 'Z')) { printf(%c is ALPHABET.n, ch); } else if(ch = '0' ch = '9') { printf(%c is DIGIT.n, ch); } else { printf(%c is SPECIAL CHARACTER.n, ch); } } 8.3  Programs for practice 1. To accept a matrix of mXn order, n and m are user defined, from user. Calculate and print their row sum, column sum and diagonal sum. 2. To accept a matrix of mXn order, where n and m are user defined, from user. Print its transpose. 3. To accept any string from user and print its length. 4. To accept any string from user and print the string in reverse order. 5. To accept any string from user and insert any n characters from mth position from it. ( n and m should be less than length of the string ) 6. Read a set of 5 lines from user and print out the longest line.
  • 85. CHAPTER – 9 USER DEFINED FUNCTIONS 9.1 Definition Self-contained block of statement used to perform a particular task is called as function. The biggest advantage of function is code reusability. It divides the large program into segments because of this it becomes easy for a programmer to debug the program. Functions are sometimes called as methods. Functions are divided into following category i. Call by value and ii. Call by reference/ call by address: i. Call by value: In this category of the function the copy of variable value is being passed to the called function. This divided into following categories depending on the return type and parameter it carries. 1. Function with no return and parameter 2. Function with no return but carrying parameter 3. Function with return but carrying no parameter 4. Function with return as well as parameter ii. Call by reference / call by address: In this category of function the address of the variable is passed to the called function. Sometime address is also called as reference of variable. Program 9.1 Call by value: Function category 1: Write a program to perform addition of two numbers. #includestdio.h #includeconio.h void add(void); main() { add(); } void add() { int a,b,c; printf(enter the value of a,b); scanf(%d%d,a,b); c=a+b; printf(n addition is: =); printf(%d,c); }
  • 86. Computer Concepts and Fundamentals of Programming 80 Note: Same program can be written by using fourth category 9.2 Call by value: Function category 4: Write a program to perform addition of two numbers. #include stdio.h #include conio.h int ganesh(int a,int b); main() { int x=4,y=8,z; z=ganesh(x,y); // here x and y are called as actual parameter ,ssss printf(%d,z); } int ganesh(a,b)// here a and b are called as formal parameters { int c=a+b; return c; } 9.3 Call by reference: Write a function program with call by reference to swap the values of two integer variable. In call by reference, the operation performed on formal parameters, affects the value of actual parameters because all the operations performed on the value stored in the address of actual parameters. #include stdio.h #include conio.h void swapnum ( int *var1, int *var2 ) { int tempnum ; tempnum = *var1 ; *var1 = *var2 ; *var2 = tempnum ; } int main( ) { int num1 = 35, num2 = 45 ; printf(Before swapping:); printf(nnum1 value is %d, num1); printf(nnum2 value is %d, num2); /*calling swap function*/ swapnum( num1, num2 ); printf(nAfter swapping:); printf(nnum1 value is %d, num1); printf(nnum2 value is %d, num2); getch(); return 0; }
  • 87. User defined function 81 9.3  Parameter and its types Parameters are nothing but the variables. Depending upon the location of the declaration they are classified as: 1. Local parameter: Any variable declared within the function body is a local parameter. Its scope lies up to that function body only where it is declared. 2. Global parameter: Any viable declared outside the function body is called as global parameter. 3. Actual parameter: The parameter which are being passed to the called function are calle as actual parameter. 4. Formal parameter: The parameter which are accepting the value of actual parameter are called as formal parameter. Following example best illustrates the functioning of the different parameters #include stdio.h #include conio.h int pi;// This is a global variable int ganesh(int a,int b); main() { int x=4,y=8,z;// x,y,z atre called as local parameter z=ganesh(x,y); // here x and y are called as actual parameter, ssss printf(%d,z); } int ganesh(a,b)// here a and b are called as formal parameters { int c=a+b; return c; } 9.4 Recursion Recursion: Function which is called within its own body is called as recursion. Program 8.3.1 //This program is for the recusive function //function called within its own body #includestdio.h main() { printf(nThis is a recursive function will run infinitenn); main(); } 9.3.2  Program Fibonacci series /*This program is showing the execution of recusive function*/ #includestdio.h
  • 88. Computer Concepts and Fundamentals of Programming 82 #includeconio.h int Fibonacci(int); int main() { int n, i = 0, c; scanf(%d,n); printf(Fibonacci seriesn); for ( c = 1 ; c = n ; c++ ) { printf(%dn, Fibonacci(i)); i++; } return 0; } int Fibonacci(int n) { if ( n == 0 ) return 0; else if ( n == 1 ) return 1; else return ( Fibonacci(n-1) + Fibonacci(n-2) ); } 9.4  Programs for practice WAP to check whether the given number is (Using all the four categories of function) 1. PRIME NUMBER 2. ARMSTRONG NUMBER 3. PALINDROME NUMBER 4. SPECIAL NUMBER 5. MAGIC NUMBER 6. PERFECT NUMBER 7. ADAM NUMBER
  • 89. CHAPTER – 10 POINTERS 10.1 Introduction The computer’s memory is a collection of storage cell. Each cell or location has a unique address. The address is a consecutive numerical number often expressed in hexadecimal, which is difficult to use directly in the program. To ease the burden of programming using numerical address, the concept of variables is introduced. A variable is a named location that can store a value of a particular type. Instead of numerical addresses, names are attached to certain addresses. Also, data types such as int, double, char are related with the contents for the interpretation of data. Pointer is defined as address variable, a variable which holds the address of another variable. The following diagram illustrate the relationship between computers' memory address and content; and variable's name and value used by the programmers. Address Name Value /content 7000000 7000001 a 25 7000002 7000003 7000004 b 3 7000005 int a=25, b=3; 7000001 is the address of variable named “a” whose value is 25. If this address 7000001 is be stored in a variable, then the variable has to be a pointer or pointer variable. 10.2  Pointer declaration Like any other variable the pointer variable also should be declared before use. Syntax to declare a pointer data_type * pointer_var_name; Example int * p; The character asterisk (*) tells to the compiler that the identifier “p” should be declare as pointer. The data type tells to the compiler that pointer “p” will store memory address of an integer variable.