PSC-UNIT-1
PSC-UNIT-1
a. Preamble :
Modern world aims to replace computer for human works. Any real world problem can be
solved using computers most effectively. The areas like weather forecast, defence,
construction, medical, business, marketing, education, entertainment makes use of the
computer for more than three decades. To solve the real world problem through
programming in an efficient manner, basic knowledge of computing is required. This
course provides adequate knowledge to solve the problems in respective domains. C is a
language which begins from scratch and it has foundational concepts on which today
concepts stand on. C is the mother of all programming languages since most dominant
languages and system softwareare written in C.
b. Prerequisite Courses:
Higher Secondary Level Mathematics
d. Course Outcomes :
Upon the successful completion of the course, students will be able to:
Knowledge Level
CO (Based on revised
Course Outcomes
No’s Bloom’s
Taxonomy)
Describe the basics of computer, problem solving technique and K2
CO1 represent the algorithm, flow chart and pseudocode for the given
problem.
Design and develop C program to evaluate simple arithmetic and K2
CO2 logical problems
Develop C programs using arrays and practice to decompose the K3
CO3
problem into functions
Demonstrate the usage of structures and understand the concept of K3
CO4 pointer
Perform I/O operations in files and learn the basics of graphics in K3
CO5 C
E. Course Content:
Theory
Text Books:
Online resources
1. https://www.learn-c.org/
2. https://www.cprogramming.com/tutorial/c-tutorial.html
3. https://www.tutorialspoint.com/cprogramming/index.htm
4. https://computer.howstuffworks.com/c1.htm
5. http://www.tutorialspoint.com/computer_fundamentals/
6. https://www.programiz.com/c-programming
UNIT-1
1.Speed:- As you know computer can work very fast. It takes only few seconds for calculations
that we take hours to complete. You will be surprised to know that computer can perform millions
(1,000,000) of instructions and even more per second. Therefore, we determine the speed of
computer in terms of microsecond
2. Accuracy:- The degree of accuracy of computer is very high and every calculation is
performed with the same accuracy. The accuracy level is 7. determined on the basis of design of
computer. The errors in computer are due to human and inaccurate data.
3. Diligence - A computer is free from tiredness, lack of concentration, fatigue, etc. It can work
for hours without creating any error. If millions of calculations are to be performed, a computer
will perform every calculation with the same accuracy. Due to this capability it overpowers
human being in routine type of work.
4. Versatility:- It means the capacity to perform completely different type of work. You may use
your computer to prepare payroll slips. Next moment you may use it for inventory management or
to prepare electric bills.
5. Power of Remembering - Computer has the power of storing any amount of information or
data. Any information can be stored and recalled as long as you require it, for any numbers of
years. It depends entirely upon you how much data you want to store in a computer and when to
lose or retrieve these data.
6. No IQ - Computer is a dumb machine and it cannot do any work without instruction from the
user. It performs the instructions at tremendous speed and with accuracy. It is you to decide what
you want to do and in what sequence. So a computer cannot take its own decision as you can.
7. Storage:- The Computer has an in-built memory where it can store a large amount of data. You
can also store data in secondary storage devices such as floppies, which can be kept outside your
computer and can be carried to other computers.
Application of Computers
Education : Getting the right kind of information is a major challenge as is getting information to
make sense. College students spend an average of 5-6 hours a week on the internet. Research
shows that computers can significantly enhance performance in learning. This offers a variety of
internet and video-based online courses.
Health and Medicine : Computer technology is radically changing the tools of medicine. All
medical information can now be digitized. Software is now able to computer the risk of a disease.
Mental health researchers are using computers to screen troubled teenagers in need of
psychotherapy. A patient paralyzed by a stroke has received an implant that allows
communication between his brain and a computer; as a result, he can move a cursor across a
screen by brainpower and convey simple messages.
Science: Scientists have long been users of it. A new adventure among scientists is the idea of a
“collaboratory”, an internet based collaborative laboratory, in which researchers all over the world
can work easily together even at a distance. An example is space physics where space physicists
are allowed to band together to measure the earth‟s ionosphere from instruments on four parts of
the world.
Business: Business clearly see the interest as a way to enhance productivity and competitiveness.
Some areas of business that are undergoing rapid changes are sales and marketing, retailing,
banking, stock trading, etc. Sales representatives not only need to be better educated and more
knowledgeable about their customer‟s businesses, but also must be comfortable with computer
technology. The internet has become a popular marketing tool. The world of cybercash has come
to banking – not only smart cards but internet banking, electronic deposit, bill paying, online
stock and bond trading, etc.
Government: Various departments of the Government use computer for their planning, control
and law enforcement activities. To name a few – Traffic, Tourism, Information & Broadcasting,
Education, Aviation and many others. Defence: There are many uses computers in Defence such
as:
• Controlling UAV or unmanned air-crafts an example is Predator. If you have cable I would
recommend watching the shows “Future Weapons" and “Modern Marvels". The show future
weapon gives an entire hour to the predator.
• They are also used on Intercontinental Ballistic Missiles (ICBMs) that uses GPS and Computers
to help the missile get to the target.
• Computers are used to track incoming missiles and help slew weapons systems onto the
incoming target to destroy them.
Sports: In today's technologically growing society, computers are being used in nearly every
activity. Recording Information : Official statistics keepers and some scouts use computers to
record statistics, take notes and chat online while attending and working at a sports event.
Analyzing Movements : The best athletes pay close attention to detail. Computers can slow
recorded video and allow people to study their specific movements to try to improve their
tendencies and repair poor habits.
Applications
Used in the field of desktop publishing, accounting, statistical analysis, graphic designing,
investment analysis, project management, teaching, entertainment etc.,
The different models of microcomputers are given below:-
a) Personal computers:- The name PC was given by the IBM for its microcomputers. PCs are used
for word processing, spreadsheet calculations, database management etc.
b) Note book or Lap Top:- Very small in terms of size – can be folded and carried around –
Monitor is made up of LCD and the keyboard and system units are contained in a single box.
1.1.2 Generation Of Computers
The first electronic computer was designed and built at the University of Pennsylvania based on
vacuum tube technology. Vacuum tubes were used to perform logic operations and to store data.
Generations of computers has been divided into five according to the development of
technologies used to fabricate the processors, memories and I/O units.
1. I Generation : 1945 – 56
2. II Generation : 1956 – 63
3. III Generation : 1963 – 75
4. IV Generation : 1975 – 89
5. V Generation : 1989 to present
Example:
ENIAC - Electronic Numerical Integrator And Calculator
EDSAC – Electronic Delay Storage Automatic Calculator
EDVAC – Electronic Discrete Variable Automatic Computer
UNIVAC – Universal Automatic Computer
IBM 701
1. Input Unit
An input unit is an electronic device, which is used to feed input data and control signals
to a computer.
Computers need data and instructions in order to solve any problem. We need to put the
data and instructions into the computers. The input unit consists of one or more input devices. All
input devices perform the following functions:
1. Accept data and instruction from the outside world.
2. Convert it to a form that the computer can understand.
3. Supply the converted data to the computer system for further processing
Input Devices
Following are the common input devices which are used in Computer Systems
Keyboard
Mouse
Joy Stick
Light pen
Track Ball
Scanner
Graphic Tablet
Microphone
Magnetic Ink Card Reader (MICR)
Optical Character Reader (OCR)
Bar Code Reader
Optical Mark Reader
Keyboard
Most common and very popular input device is keyboard. The keyboard helps in inputting
the data to the computer. The layout of the keyboard is like that of traditional typewriter, although
there are some additional keys provided for performing some additional functions.
Keyboards are of two sizes 84 keys or 101/102 keys, but now 104 keys or 108 keys
keyboard is also available for Windows and Internet.
Mouse
Mouse is most popular Pointing device. It is a very famous cursor-control device. It is a
small palm size box with a round ball at its base which senses the movement of mouse and sends
corresponding signals to CPU on pressing the buttons. Generally it has two buttons called left and
right button and scroll bar is present at the mid. Mouse can be used to control the position of
cursor on screen, but it cannot be used to enter text into the computer.
Fig: Mouse
Light Pen
Light pen is a pointing device which is similar to a pen. It is used to select a displayed
menu item or draw pictures on the monitor screen. It consists of a photocell and an optical system
placed in a small tube.
When light pen's tip is moved over the monitor screen and pen button is pressed, its
photocell sensing element detects the screen location and sends the corresponding signal to the
CPU
Digitizer
Digitizer is an input device which converts analog information into a digital form.
Digitizer can convert a signal from the television camera into a series of numbers that could be
stored in a computer. They can be used by the computer to create a picture of whatever the
camera had been pointed at. Digitizer is also known as Tablet or Graphics Tablet because it
converts graphics and pictorial data into binary inputs. A graphic tablet as digitizer is used for
doing fine works of drawing and images manipulation applications
Fig: Digitizer
1) Primary Memory
2)Secondary Memory
1) Primary Memory:
Primary memory is also known as primary storage or main memory.
Primary memory is computer memory that a processor or computer accesses first or directly.
It hold the program being currently executed in the computer. The program that you want to
run on the computer is first transferred to the primary memory before it can run.
This primary memory is temporarily store the data for processing by CPU.
Each &ever information can process through any main memory.
It is fast & expensive.
As soon as a computer starts, primary memory loads all running applications, including the
base operating system (OS), user interface and any user-installed and running software utility.
A program/application that is opened in primary memory interacts with the system processor
to perform all application-specific tasks.
RAM ROM
Volatile storage. Data is erased as soon as Non-volatile storage. Data remains stored even
power supply is turned off. after power supply has been turned off.
Cache Memory
• Cache memory holds frequently requested data and instructions so that they are immediately
available to the CPU when needed.
• Cache memory is an extremely fast memory that acts as a buffer between RAM and the
CPU, which is placed between CPU and the main memory.
• Cache memory is used to reduce the average time to access data from the Main memory.
(iv) Secondary Memory
The secondary storage represents the external storage devices that are connected to the
computer.
It may store several programs, documents, database, etc.
It is the permanent storage; the data stored in this storage will not be erased when the
power is lost. It is a non-volatile memory.
The secondary memory is slower than the primary memory.
Example: Some of the commonly used secondary memory devices are Floppy disk, Hard disk
drive, Compact Disk (CD), Digital Video Disk (DVD).
3. Output unit
These devices used to get the response or result from the processor. Output unit is the
communication between the user and the computer. The output unit of a computer provides the
information and results of a computation to the outside world. It converts information into human-
readable form. It can be text, graphics, tactile, audio, and video.
Commonly used output devices are,
Monitor
Graphic Plotter
Printer
Speaker
Headphone
Projector
Touchscreen
Fig: CRT Monitor
Non-impact Printers
The printers that print the characters without striking against the ribbon and onto the paper are
called Non-impact Printers. These printers print a complete page at a time, also called as Page
Printers.
These printers are of two types
Laser Printers
Inkjet Printers
Characteristics of Non-impact Printers
Faster than impact printers.
They are not noisy.
High quality.
Support many fonts and different character size.
Laser Printers
These are non-impact page printers. They use laser lights to produces the dots needed to form the
characters to be printed on a page.
Advantages
Very high speed.
Very high quality output.
Give good graphics quality.
Support many fonts and different character size.
Disadvantage
Expensive.
Cannot be used to produce multiple copies of a document in a single printing .
1. Machine languages
The machine language is formed with the help of binary digits. This is also called as the
low level language. This language is the collection of instruction using binary digits 0’s and 1’s.
There are as named as the machine can directly understand the programs.
Advantages of machine language:
1. The computer can understand instruction immediately.
2. No translation is needed
Disadvantages of machine language:
1. Machine dependent
2. Writing a Programming is very difficult
3. Very difficult to find an error.
Example: add 4 and 9
0100
1001
_____________
1101
______________
2. Assembly Language
It was developed to overcome some of the many inconveniences of machine language.
This is another low level but a very important language in which operation codes and operands
are given in the form of alphanumeric symbols instead of 0’s and l’s. These alphanumeric symbols
will be known as mnemonic codes and can have maximum up to 5 letter combination e.g. ADD
for addition, SUB for subtraction, START, LABEL etc. Because of this feature it is also known as
‘Symbolic Programming Language’.
This language is also very difficult and needs a lot of practice to master it because very
small. English support is given to this language. The language mainly helps in compiler
orientations. The instructions of the Assembly language will also be converted to machine codes
by language translator to be executed by the computer.
Advantages of Assembly Language
i) It is easier to understand and use as compared to machine language.
ii) It is easy to locate and correct errors. iii) It is modified easily.
Disadvantages of Assembly Language
i) Like machine language it is also machine dependent.
ii) Since it is machine dependent therefore programmer should have the knowledge of the
hardware also
Example: addition of 4 and 9 Say A=4 B=9
MVI A move A value to Accumulator
ADD B add B with Accumulator
STA C Store Accumulator contents to C
HLT Halt the program.
The digit
Its position in the number
The base of the number system
There are various types of number systems in mathematics. The four most common number
system types are:
Thus (55)8 = 40 + 5. = 45
Conversions of Octal Fractions to Decimal Fractions- The weight of the bit of the fraction
placeholder is 8-1, 8-2………. We follow the same steps of conversion of binary fractions to
decimal fractions.
Example- Convert (55.6)8 into decimal number system
Thus (55.6)8= 40 + 5 + 0.75 = 45.75
6. Conversions of Octal to Binary- We use the following steps in converting octal to binary-
(a) Convert each octal digit into 3-bit binary equivalent.
(b) Combine the 3-bit section by removing the spaces to get the binary number.
Example- Convert (55)8 into binary.
Conversions of Octal Fractions to Binary Fractions- We follow the same steps of conversion
of octal to binary.
Example- Convert (55.6)8 into binary
Octal 5 5 6
Number
Binary 101 101 110
Number
Thus (55.6)8 = (101101.11)2.
7.Conversions of Binary to Octal- We use the following steps in converting binary to octal-
(a) Break the number into 3-bit sections starting from LSB to MSB.
(b) If we do not have sufficient bits in grouping of 3-bits, we add zeros to the left of MSB so
that all the groups have proper 3-bit number.
(c) Write the 3-bit binary number to its octal equivalent.
Example- Convert (101101110)2 into octal.
Binary 101 101 110
Number
Octal Number 5 5 6
Thu
s (2D.C)16= 32 + 13 + 0.75 = 45.75.
Values
Values are the actual data or content that variables hold. They can be of various data types, such
as:
1. Integers: Whole numbers (e.g., 10, -3).
2. Floats: Numbers with decimal points (e.g., 3.14, -0.001).
3. Strings: Sequences of characters (e.g., "Hello, World!").
4. Booleans: True or False values.
Instructions:
Instructions are commands given to the computer to perform specific operations. These
can include arithmetic operations, data movement, and control operations. Instructions are written
in programming languages and are executed by the CPU.The instruction execution takes place in
the CPU registers.
The CPU reads (fetches) instructions (codes) from the memory one at a time, and executes
or performs the operation specified by this. Instruction fetch involves reading of an instruction
from a memory location to the CPU register.
Programs:
Programs are sets of instructions that are executed by a computer to perform specific
tasks. Programs are written in programming languages and can range from simple scripts to
complex applications. A program typically consists of multiple instructions that work together to
achieve a goal.
1.6 Problem Solving Techniques
1. Sequence structure
2. Selection structure
3. Repetition structure
Sequence refers to the execution of code statements one after another in a specific order. This is
the simplest form of control structure where instructions are executed in the same order in which
they appear.
2. Selection
Selection involves making decisions based on conditions. It allows the program to choose
different paths of execution. The primary selection constructs are if, else if, else, and switch. The
if-else statement in C is used to perform the operations based on some specific condition. The
operations specified in if block are executed if and only if the given condition is true.
There are the following variants of if statement in C language.
If Statement
The if statement is used to check some given condition and perform some operations
depending upon the correctness of that condition. It is mostly used in the scenario where we need
to perform the different operations for the different conditions. The syntax of the if statement is
given below.
If-else Statement
The if-else statement is used to perform two operations for a single condition. The if-else
statement is an extension to the if statement using which, we can perform two different
operations, i.e., one is for the correctness of that condition, and the other is for the incorrectness
of the condition. Here, we must notice that if and else block cannot be executed simultaneously.
Using if-else statement is always preferable since it always invokes an otherwise case with every
if condition. The syntax of the if-else statement is given below.
3. Repetition
While Loop
•
Do-WHILE Loop
• The statement given in the Do block are executed atleast once and after that repeatedly
executed until the given condition is true.
• The condition is always executed after the body of a loop. It is also called an exit-
controlled loop.
• At each instance of execution of block statements, the condition is checked.
• If the condition is true, then only block statement are executed; otherwise the repetition
structure is terminated.
for Loop
• The initial value is performed only once, then the condition tests and compares the counter
to a fixed value after each iteration, stopping the for loop when false is returned.
1.8. FLOWCHART
A flowchart is the graphical representation of the flow of control and logic for solving a
problem. It is a pictorial representation of an algorithm.
It is a generic tool that can be adapted for a wide variety of purposes, and can be used to
describe various processes, such as a manufacturing process, an administrative or service
process, or a project plan.
USE A FLOWCHART
To develop understanding of how a process is done and study a process for improvement
To communicate to others how a process is done
When better communication is needed between people involved with the same process
and to document a process when planning a project.
More Flowchart symbols
Flowchart
1.9 ALGORITHM
It is defined as a sequence of instructions designed in such a way that if the instructions
are executed in the specified sequence, the desired results will be obtained. The algorithm should
precise and unambiguous in practice and the results should obtain after a finite number of steps.
An algorithm is defined if any problem whose solution can be expressed in a list of executable
instruction.
Characteristics of algorithms
In order to qualify algorithms is a sequence of instructions, they must possess the following
characteristics:
i) In the algorithms, each and every instruction should be precise.
ii) Each and every instruction should be unambiguous
iii) Ensure that the algorithm will ultimately terminate.
iv) The algorithm should be written in sequence.
v) It looks like normal English
vi) The desired result should be obtained only after the algorithm terminates
Representation of algorithms
The algorithms can be represented in several ways. Generally the programmers follows one of the
following ways to represent an algorithms:
i) Normal English
ii) Flowchart
iii) Pseudo code
iv) Decision table
v) Program
A sample algorithm
Write an algorithm to calculate and print the total number of students selected in various group,
using the following criteria. In a school there are 100 student appeared for examination. Based
upon the student marks who secure greater than 70% as first class, greater than 60% as second
class, and greater than 50% as third class and remaining are fail.
Algorithm
Step 1: Start the program
Step 2: Read number of students, name of the student, marks.
Step 3: calculate the total marks obtained by each student.
Step 4: check student mark is greater than 70 or not. If greater than 70 then “first class”.
Step 5: check student mark is greater than 60 and less than 70or not. If so then, “second class”.
Step 6: check student mark is greater than 50 and less than 60 or not. If so then, “third class”.
Step 7: print the result of the student with their names and marks.
Step 8: Stop the program
1.10 PSEUDOCODE
Pseudocode is a simplified, informal way of representing the logic of a program using
plain language.
It is used to describe the steps that are to be performed for solving a problem (i.e.,) flow of
a program without worrying about syntax details specific to any programming language.
It uses short phrases to write code for programs before you actually create it in a specific
language.
Characteristics of Pseudocode
Simplicity: Easy to read and understand.
Language-agnostic: Not tied to any specific programming language.
Clarity: Clearly represents the logic and structure of the algorithm.
Basic Constructs in Pseudocode
• Pseudocode will be enclosed by START (or BEGIN) and STOP (or END).
• To accept data from user, generally used statements are INPUT, READ, GET or OBTAIN.
• To display result or any message, generally used statements are PRINT, DISPLAY, or
WRITE.
• Generally used keywords are capitalized while preparing pseudocode.
• Pseudocode should be concise so ignore unnecessary details.
1. Sequence: Execution of instructions one after another.
2. Selection: Decision-making using IF-THEN-ELSE, END IF , CASE, ELSE IF.
3. Repetition: Looping constructs like FOR, END FOR, WHILE, END WHILE , REPEAT –
UNTIL.
Example: 1 Pseudocode to add two numbers.
BEGIN
Get the value from the user(a,b)
c=a+b
print c
END
Example: 2 Pseudocode to find square root of a number.
BEGIN
READ num
result=SQRT(num)
DISPLAY result
END
1. Start.
2. Read numbers a and b.
3. Calculate the sum of a and b. sum=a+b
4. Print the value of sum.
5. Stop
Pseudocode:
BEGIN
DECLARE variables A, B, and sum as INTEGER
READ A, B
COMPUTE
sum = A + B
PRINT sum
END
Flowchart:
2. Selection Structure:
Example: Check whether the given number is even or odd.
Algorithm
1. Start
2. Read an integer number from the user.
3. Check if number is divisible by 2.
4. If number % 2 == 0 (i.e., the remainder when number is divided by 2 is 0), then number is
even.
5. Otherwise, number is odd.
6. Print whether the number is even or odd.
7. End
Pseudocode:
BEGIN
READ number
IF (number % 2 == 0) THEN
PRINT “number is even."
ELSE
PRINT “number is odd."
END IF
END
Flowchart:
3. Repetition Structure:
Example: Print the numbers from 1 to 10.Algorithm:
1. Start
2. Initialize the variable i to 1.
3. Repeat the following steps 5 & 6 while i is less than or equal to 10 then go to step 7.
4. Print the value of i.
5. Increment i by 1.
6. End
Pseudocode:
BEGIN
FOR i = 1 TO 10 DO
PRINT i
END FOR
END
Flowchart: