Group B Assignment No.1
Group B Assignment No.1
GROUP B
ASSIGNMENT NO.1
AIM:
Write a C prgra! t a""ept #ive nu!$er% #r! "n%&e an' t(en t 'i%p&a) t(e!
$a"* n "n%&e in a%"en'ing r'er.
T+EOR,:
To write a program in C languages following basics should be known---
1) Algorithm
2) Flowchart
3) Header files
) main!) function
") #ata-t$pes
%) &ariable declaration
') (etch!) function
)) Clrscr!) function
*) +rintf!) , scanf!) functions
1- A&grit(!:
Algorithm is the step-b$-step description of se-uences of instructions.
#esigned to get the desired instructions/ The characteristics of algorithms are as follows-
a) 0ach , e1er$ instruction should be precise and unambiguous/
b) 0ach instruction should be such that it can be performed in a finite time/
c) 2ne or more instructions should be repeated infinitel$/ This ensures that the
algorithm will ultimatel$ terminate/
d) After performing the instructions. that is. after the algorithm terminates. the
desired results must be obtained/
The algorithms can be represented3
a) As programs 4 5tep-b$-step instructions
b) As flowcharts 4 +ictorial representation of an algorithm
c) As pseudo codes 4 programming anal$sis tool. used for planning programming
logic/
.- /&0"(art:
Flow-chart is often used b$ programmers as a program-planning tool for organi6ing a
se-uence of steps necessar$ to sol1e a problem b$ a computer/ 7t uses bo8es of different
shapes to denote different t$pes of instructions/ The actual instructions are written within
these bo8es using clear , concise statements/ These bo8es are connected b$ solid lines
ha1ing arrow marks to indicate the flow of operation that is the e8act se-uence in which
the instructions are to be e8ecuted/ The process of drawing a flowchart for an algorithm is
often referred to as 9flowcharting/:
Flowchart to be used for reducing the number of errors , it ser1es as a document for
the computer program/ 7t is also 1er$ useful during the testing , modif$ing the program/
1
MMCOE, KarveNagar, Pune
The main ad1antage of this approach is that while drawing a flowchart. the
programmer is not concerned with the details of the elements of the programming
languages/
a- /&0"(art S)!$&%:
The communication of program logic through flowcharts is made easier b$ the
use of s$mbols. which ha1e standardi6ed meanings/ This is because. as long as e1er$one
uses the same basic shapes. others can readil$ interpret the logic/ These flowchart
s$mbols are as follows4
I- Ter!ina&:
The terminal s$mbol is used to indicate the beginning !start). end !stop). and
pauses !halt) in the program logic flow/ 7t is the first s$mbol and last s$mbol in the
program logic/ 7n addition. if the program logic calls for a pause in the program. the
pause is also indicated with a terminal s$mbol/ A pause is used in the program logic
under some error conditions. or if the forms had to be changed in the computer;s line
printer during the processing of that program/
II- 1e"i%in:
The decision s$mbol is used in a flowchart to indicate a point at which a decision
has to be made. and a branch to one of two or more alternati1e points is possible/ There
are three different wa$s in which the decision s$mbol can be used---
2
Terminal
Flow <ines Connectors
#ecision 7nput=2utput
+rocessing
MMCOE, KarveNagar, Pune
7t ma$ be noted that the condition upon which each of the possible e8it paths will be
e8ecuted should be identified/ #uring e8ecution. the appropriate path is followed
depending upon the result of the decision/
III- Input2Output:
The input=output s$mbol is used to denote an$ function of an input=output de1ice
in the program/ 7f there is a program instruction to input data from a disk. tape. terminal
or an$ other t$pe of input de1ice. that step will be indicated in the flowchart with this
s$mbol/ 5imilarl$. all output instructions. whether it is output on a printer. magnetic tape.
magnetic disk. terminal screen. or an$ output de1ice. are indicated in the flowchart with
the input=output s$mbol/
I3- Pr"e%%ing:
7t is used to represent arithmetic and data mo1ement instructions/ Hence all
arithmetic processes of adding. subtracting. multipl$ing and di1iding are shown b$ a
processing s$mbol/ The logic process of mo1ing data from one location of the main
memor$ to another is also denoted b$ this s$mbol/ >hen more than one arithmetic and
data mo1ement instructions are to be e8ecuted consecuti1el$. the$ are normall$ placed in
the same processing bo8. and the$ are assumed to be e8ecuted in the order of their
appearance/
3- /&0 4ine%:
?es
@o
AAB
ACB ADB
Compare
A , B
7s
7A1EF
A two-wa$ branch decision A three-wa$ branch decision
7AF
AE A1 A2 A3 A A" A2ther
A multiple-wa$ branch decision
3
MMCOE, KarveNagar, Pune
Flow lines with arrowheads are used to indicate the flow of operation. that is. the
e8act se-uence in which the instructions are to be e8ecuted/ The normal flow of
flowchart is from top to bottom and left to right/ The flow lines should not cross each
other. thus the intersection should be a1oided whene1er possible/
3I- Cnne"tr%:
>hene1er the flowchart becomes comple8 enough that the number and direction
of flow lines is confusing. or it spreads o1er more than one page. it is useful to utili6e the
connector s$mbol as a substitute for flow lines/ This s$mbol represents an entr$ from. or
an e8it to another part of the flowchart/ A connector s$mbol is represented b$ a circle.
and letter or digit is placed within the circle to indicate the link/ A pair of identicall$
labeled connector s$mbol is commonl$ used to indicate a continued flow. when the use
of line is confusing/
5- +ea'er /i&e%:
7n C language the header files are defined b$ 9Ginclude: directi1e/ The 9Ginclude:
directi1e tells the compiler to read another source file/ The name of the source file must
be enclosed between double -uotes or angle brackets/ For e8ample-
Ginclude 9stdio/h:
Ginclude Dstdio/hC
Both cause the compiler to read and compile the header for the 7=2 s$stem librar$
functions/
6- !ain7- #un"tin:
7n C language. the program e8ecution alwa$s stars with main !) function/
8- 1ata9t)pe%:
C)* defines fi1e foundational data t$pes4 character. integer. floating-point. double
floating-point. and 1alueless/ These are declared using char. int. double and 1oid
respecti1el$/ These t$pes form the basis for se1eral other t$pes/ The si6e and range of
these data-t$pes ma$ 1ar$ among processor t$pes and compilers/ 08cept 91oid:. the basic
data t$pes ma$ ha1e 1arious modifiers preceding them like signed. unsigned. long and
short/ These data-t$pes and their corresponding minimal ranges are as follows3
T)pe T)pi"a& %i:e in Bit% Mini!a& Range
char ) -12' to 12'
unsigned char ) E to 2""
signed char ) -12' to 12'
int 1% to 32 -32'%' to 32'%'
unsigned int 1% to 32 E to %""3"
signed int 1% to 32 5ame as int
short int 1% -32'%' to 32'%'
long int 32 -2.1'.3).%' to 2.1'.3).%'
float 32 10-3' to 10H3' with si8 digits of
precision
double % 10-3' to 10H3' with ten digits of