Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 24

PROGRAMMING

IN C
B.SC(MATHS)-
CA102
Prepared by : Ms.Pooja Gupta 1
INTRODUCTION TO COMPUTER
PROGRAMMING
Computer
A computer is an electronic device operating under the control of
instructions stored in its
memory. It has the following characteristics:
 A computer has input and output circuitry
 A computer has a central processing unit for carrying out arithmetical and
logical operations
 A computer has memory for the storage of programs and data
 A computer can execute sequences of instructions.

Prepared by : Ms.Pooja Gupta 2


The basic components of a computer

Prepared by : Ms.Pooja Gupta 3


Central Processing Unit (CPU) is the part of the computer that executes the instructions (program)
stored in memory. The CPU is made up of the Control Unit and the Arithmetic/Logical Unit.
Control Unit is the component of the CPU that controls the actions of the other components so
that instructions are executed in the correct sequence.

Arithmetic/Logical Unit (ALU) is the component of the CPU that performs arithmetic and
logical operations.

Memory Unit is used for internal data storage in a computer. The memory is comprised of a
large number of individual cells, each with a unique number, known as its address, associated with
it.

Each memory cell is made up of a set number of binary digits (bits). A Bit can store one of two
values, denoted by a 1 or 0.The Memory Unit stores several different types of data:

 Numbers- integers, reals, etc


 Characters - alphabetic, punctuation, special symbols
 Logical data - True/False results.
 Instructions - Program data that instructs the computer as to what to do.
Prepared by : Ms.Pooja Gupta 4
A computer's memory is volatile, that is, its contents are lost when power is turned
off and thus the need for storage devices. Storage devices fall under the peripherals.

Peripheral Devices are the equipment attached to a computer and include the
following:
Input Devices - Instruments for entering data into a computer.
 Keyboard
 Mouse
 Microphone
 Scanners
 CD-ROM Drive
 Web-Cam etc.
 Joystick
 Touch screen
 Output Devices - Components for displaying or presenting data to users.
 Monitor
 Printer
 Speaker
 CD-ROM Burner etc. Prepared by : Ms.Pooja Gupta 5
Storage Devices - Components for long-term storage of data.
 Floppy Disk
 Hard Disk
 Rewritable Optical Disk
 Flash drive
 Memory Card etc.

Prepared by : Ms.Pooja Gupta 6


PROBLEM SOLVING USING COMPUTER

 Number of problems in our daily life

 Suppose we have to calculate Simple Interest.

 Suppose we have to prepare a mark sheet.

 A computer is a DUMB machine.

 A computer cannot do anything alone without software i.e.


Program

Prepared by : Ms.Pooja Gupta 7


SOFTWARE
 A software is a set of programs written to solve a particular
problem

 Software is a set of instructions on the basis of which computer


gives output/result.

 If the instructions are not correct, the computer gives wrong


result

Prepared by : Ms.Pooja Gupta 8


COMPUTER PROGRAM
A Computer program is a sequence of instructions which the CPU
interprets as arithmetical and logical operations. A computer program is
stored in memory and also consists of data and instructions.

Prepared by : Ms.Pooja Gupta 9


COMPUTER PROGRAM DEVELOPMENT LIFE
CYCLE

Prepared by : Ms.Pooja Gupta 10


PROBLEM ANALYSIS
 Process of becoming familiar with the problem

 We need to analyze and understand it well before solving

 The user’s requirements cannot be fulfilled without clear understanding


of his/her problem in depth.

 Inadequate identification of problem may cause program less useful


and insufficient.

Prepared by : Ms.Pooja Gupta 11


ALGORITHM
 is any well-defined computational procedure that takes some value, or set of
values, as input and produces some value, or set of values, as output.

 is thus a sequence of computational steps that transform the input into the
output.

 is a tool for solving a well - specified computational problem.

 is a sequence of unambiguous instructions for solving a problem, i.e., for


obtaining a required output for any legitimate input in a finite amount of
time.
 There may exist several algorithms for solving the same problem

Prepared by : Ms.Pooja Gupta 12


Prepared by : Ms.Pooja Gupta 13
CHARACTERISTICS OF AN ALGORITHM
•Unambiguous − Algorithm should be clear and unambiguous. Each of its
steps (or phases), and their inputs/outputs should be clear and must lead
to only one meaning.

•Input − An algorithm should have 0 or more well-defined inputs.

•Output − An algorithm should have 1 or more well-defined outputs, and


should match the desired output.

•Finiteness − Algorithms must terminate after a finite number of steps.

•Feasibility − Should be feasible with the available resources.

•Independent − An algorithm should have step-by-step directions, which


should be independent of any programming code.

Prepared by : Ms.Pooja Gupta 14


EXAMPLE
1. If the kettle does not contain water then fill the kettle

2. Plug the kettle into the power point and switch it on.

3. If the teapot is not empty then empty the teapot.

4. Place tea leaves in the teapot.

5. If the water in the kettle is not boiling then go to step 5


6. Switch the kettle off.

7. Pour water from the kettle into the teapot.


Prepared by : Ms.Pooja Gupta 15
Algorithms show these three features:
1. Sequence (also known as Process)
2. Decision (also known as Selection)
3. Repetition (also known as Iteration or Looping)

Prepared by : Ms.Pooja Gupta 16


PROBLEM − DESIGN AN ALGORITHM TO ADD T WO NUMBERS AND DISPL AY
THE RESULT.

Step 1 − START
Step 2 − declare three integers a, b & c
Step 3 − define values of a & b
Step 4 − add values of a & b
Step 5 − store output of Step 4 to c
Step 6 − print c
Step 7 − STOP

Prepared by : Ms.Pooja Gupta 17


Step 1 − START ADD

Step 2 − get values of a & b

Step 3 − c ← a + b

Step 4 − display c

Step 5 − STOP

Prepared by : Ms.Pooja Gupta 18


FLOWCHART

Flowchart is a diagrammatic representation of sequence of


logical steps of a program. Flowcharts use simple geometric
shapes to depict processes and arrows to show relationships
and process/data flow.

Prepared by : Ms.Pooja Gupta 19


Flowchart Symbols

Prepared by : Ms.Pooja Gupta 20


EXAMPLE FLOWCHARTS

Prepared by : Ms.Pooja Gupta 21


A flowchart to calculate the average of two numbers.

Prepared by : Ms.Pooja Gupta 22


STRUCTURED PROGRAMMING
In structured programming design, programs are broken into different functions these functions
are also known as modules, subprogram, subroutines and procedures.

Each function is design to do a specific task with its own data and logic. Information can be
passed from one function to another function through parameters. A function can have local
data that cannot be accessed outside the function’s scope. The result of this process is that all
the other different functions are synthesized in an another function. This function is known as
main function. Many of the high level languages supported structure programming.

Prepared by : Ms.Pooja Gupta 23


Structured programming minimized the chances of the function affecting
another. It supported to write clearer programs. It made global variables
to disappear and replaced by the local variables. Due to this change one
can save the memory allocation space occupied by the global variable.
Its organization helped to understand the programming logic easily. So
that one can easily understand the logic behind the programs. It also
helps the new comers of any industrial technology company to
understand the programs created by their senior workers of the
industry. It also made debugging easier.

Prepared by : Ms.Pooja Gupta 24

You might also like