Вы находитесь на странице: 1из 5

##################>###

#################\###########^###########Y###Z###[###

#7
###################"####bjbjU#U################### ###"##7|##7|
#########################

#############################################l#####H#######H###H#######H#####
##########################################@e######@e######@e######@e##4###te######
#############g#######g#######g#######g#######g######g######g######g#########
##########################################$###x##
########=##############################g######################g######g######
g######g######=######z######H#######H########g###############g#####R######z#
#####z######z######g##<
##H###<####g###############g#####################z###############################
#######################g#############z##B###z#########N###########|
##########################################################################g######
#g##

###
#Ra#####,]##@e######7r#####w##0################h##0##############6##
####z######6############z######################H#######H#######H#######H######
######Programming and Problem Solving through C Language1.1 Introduction to
Computer-based problem solving; requirements of problem solving by the computer
1.1.1 Problem DefinitionThe program life cycle begins with the identification of
the problem to be computerized. This phase begins as soon as someone-either the
user of a member of the data processing department sees a problem or opportunity,
which suggests a programming solution. At such times the programmer analyst and the
user meet to develop information in response to the following three questions: What
is the problem perceived by the user? What are the goals to be achieved by the
solution? What benefits will result from achieving the solution? 1.1.2 Problem
Solving strategiesOne caution in designing a program is to avoid clever solutions
that might save a little execution time but are difficult for humans to understand.
Such programming contortions are usually hard to debug and even harder for someone
else to maintain. Thus, though programming even today is largely considered to be
an art, still some scientific methods have been developed to standardize the
designing of a program with a view to write simple, efficient, easy-to-read and
easy-to-maintain programs.Use of examples for problem solvingImagine using such a
calculator to perform the following task: Given a list of numbers, compute the
average of all the numbers, and also find the largest number in the list. You can
imagine giving the calculator a list of instructions for performing this task, or
you can imagine giving a list of instructions to a very stupid but very patient
person who is able to follow instructions blindly but accurately, as long as the
instructions consist of pushing buttons on the calculator and making simple yes/no
decisions. (For our purposes just now, either imaginary model will work.) Your
instructions might look something like this: ``We're going to use memory register 1
to store the running total of all the numbers, memory register 2 to store how many
numbers we've seen, and register 3 to store the largest number we've seen. For each
number in the input list, add it to register 1. Add 1 to register 2. If the number
you just read is larger than the number in register 3, store it in register 3. When
you've read all the numbers, divide register 1 by register 2 to compute the
average, and also retrieve the largest number from register 3.''1.3.1 Programming
Language Classification Machine Language, Assembly Language, High Level Languages
To communicate between two parties, whether they are machines or human beings, some
common language or terminology is needed. Of course this language or terminology
must be understood by both the parties. To communicate with a computer it has to be
instructed to carry out various tasks like: what operations to perform, how to
present results, when and how to make certain decisions, and so on. These set of
instructions have to be communicated to the computer through a language called
programming language. The set of instructions written in a programming language
is known as a program.There exist three levels of programming languages for
communicating the instructions to the computer. They are: Machine languages (low
level languages)Assembly languagesProcedure oriented languages (high level
languages)Let us now briefly discuss each of these languages.Machine Language
Computers are made of two-state electronic components that can understand only
pulse and no-pulse (or 1 and 0) conditions. Therefore, the instructions given to
the computer and the data fed to it must be written using binary numbers 1 and 0. A
computers machine language consists of such strings of binary numbers.Computers do
not understand English, Hindi or any other such common language. They respond only
to machine language. Added to this, computers are not identical in design.
Therefore, each computer has its own machine language. However, the script, 1 and
0, is same for all computers. This poses several problems for the users.It is very
tedious to understand and remember the various combinations of 1s and 0s
representing numerous data and instructions. In addition to remembering these
codes, the programmer is also required to keep track of the storage locations of
data and instructions. It takes several months to write programs. Also, writing
error free instructions is a slow process. Checking instructions to locate errors
is about as traumatic as writing them initially. And if a program has to be

modified at a later date, the work involved may take weeks to finish. Thus machine
language programs are difficult to write and maintain.Also, since every computer
has its own machine language, the programmer cannot communicate with other
computers if he does not know its machine language.Assembly LanguageTo ease the
programmers burden, mnemonic (pronounced ne-mon-ik) operating codes were developed
in 1950s. One of the first steps in improving the program preparation process was
to replace the numeric language operating codes with mnemonics.Thus, an assembly
language uses mnemonic codes (abbreviations) rather than numeric codes (as used in
machine language). For example, ADD is used as a symbolic operation code to
represent addition and Sub is used for subtraction. Memory locations containing
data are given names such as TOTAL, MARKS, TIME etc. Thus, instead of referring a
location using its number now it can be referred using the name given to it.For
example, the selling price of an item might be assigned to a location 0063 in
memory by the programmer, and given the symbolic name SP. And the cost price may be
assigned to a location 2047 and be given a name CP. Once this has been done the
programmer would refer to the symbolic names CP and SP rather than to the location
numbers when such items are to be processed. Thus an instruction SUBSP, CP would
subtract the value of SP from CP.As the computer understands only machine language
instructions, a program written in assembly language must be translated into
machine language before it can be executed. This translation is done by another
program called assembler. For example the instruction SUBSP, CP would be
translated by the assembler into corresponding machine language instruction as,
Assembly language has several advantages over machine language. First it saves
programmers time. Fewer errors are made, and those that are made are easier to
find. Also assembly language programs are easier to modify than machine language
programs. However, assembly language is again a machine oriented language and hence
the program has to be different for different machines. The programmer should
remember machine characteristics when he prepares a program.Third Generation
Languages or High Level LanguageThe earlier assembler programs produced only one
machine language instruction for every assembly language instruction. To speed up
program development new assemblers were developed which could produce several
machine language instruction for one assembly language instruction. For example,
the programmer might write READ FILE and the assembler would then produce a
detailed series of machine language instructions to read data from the file on the
disk and store it in memory. Thus, the programmer was relieved of the task of
writing an instruction for every machine operating performed. This development led
to the development of Third Generation languages (machine and assembly forming the
first two generations). These languages consist of a set of words and symbols and
one can write programs using these in conjunction with certain pre-specified rules
of the language. These languages are oriented towards the problem to be solved or
the procedures for the solution rather than mere computer instructions. These
languages are more user-centered than machine-centered. These languages are also
called high-level languages. The commonly used high-level languages are BASIC,
Fortran, Pascal and COBOL. The most important characteristic of a high level
language is that it is machine independent and a program written in high level
language is that it is machine independent and a program written in high level
language can be run on computers of different makes with little or no modification.
The programmer need not know the characteristics of that machine. However, such
programs are to be translated into equivalent machine language instructions before
actual execution.A program written in high-level language is known as a source
program and can be run on different machines using different translators. The
translated program is called the object program. The major disadvantage of highlevel languages is that they take extra time for conversion and thus are less
efficient as compared to the machine language programs.Fourth Generation LanguagesA
new set of languages is coming to the fore, which allow even a non-technical user
to interact with the computer in a simpler and friendlier manner. These are known
as Fourth generation languages or simply, 4GLs. These languages are non-procedural,
i.e. the users do not define the detailed procedure required to arrive at the final
result. Examples of 4GLs are dBase, FoxPro, PC/FOCUS etc.Characteristics of 3GLs

and 4GLsA programming language is a notation with which people can communicate
algorithms to computers and to one another. Hundreds of programming languages exit.
They differ in their degree of closeness to natural of mathematical language on one
hand and to machine language on the other. They differ also in the type of problem
for which they are best suited. Some of the aspects
of 3GLs and 4GLs which make them preferable to machine or assembly language are as
follows.Ease of understanding#A 3GL or 4GL program is generally easier to read,
write, and prove correct than is an assembly language program, because a high level
language usually provides a more natural notation for describing algorithms than
does assembly language. Even among high-level languages, some are easier to use
than others. Part of this has to do with the operators, data structures and flow of
control features provided in a language. Naturalness##Much of the understandability
of a 3 GL or 4GL language comes from the ease with which one can express an
algorithm in that language. Some languages are clearly more suitable than others in
this regard for differing problem domains. FORTRAN was designed for numerical and
mathematical calculations, COBOL for business applications and SNOBOL

Оценить