0% found this document useful (0 votes)
32 views

Group B Assignment No.1

This document provides information about writing a C program to accept five numbers from the user and display them in ascending order. It includes: 1) An overview of the key concepts needed for a C program like algorithms, flowcharts, header files, main() function, data types, and common functions. 2) Details on flowchart symbols and their meanings. 3) Descriptions of variables, data types, and common functions in C like scanf(), printf(), clrscr(), and getch().

Uploaded by

Geet_D
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Group B Assignment No.1

This document provides information about writing a C program to accept five numbers from the user and display them in ascending order. It includes: 1) An overview of the key concepts needed for a C program like algorithms, flowcharts, header files, main() function, data types, and common functions. 2) Details on flowchart symbols and their meanings. 3) Descriptions of variables, data types, and common functions in C like scanf(), printf(), clrscr(), and getch().

Uploaded by

Geet_D
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

MMCOE, KarveNagar, Pune

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

MMCOE, KarveNagar, Pune


precision
long double )E 10-3' to 10H3' with ten digits of
precision

;- 3aria$&e 1e"&aratin:
The entit$ that ma$ 1ar$ during program e8ecution is called a 1ariable/ &ariable
names are names gi1en to locations in memor$/ These locations can contain integer. real
or character constants/ 7n an$ language. the t$pes of 1ariables that it can support depend
on the t$pes of constants that it can handle/ This is because a particular t$pe of 1ariable
can hold onl$ the same t$pe of constant/ For e8ample. the integer 1ariable can hold onl$
an integer constant. a real 1ariable can hold onl$ a real constant and a character 1ariable
can hold onl$ a character constant/
a- Ru&e% /r Cn%tru"ting 3aria$&e Na!e%:
i) A 1ariable name is an$ combination of 1 to 31 alphabets. digits or underscores/ 5ome
compilers allow 1ariable names whose length could be up to 2' characters/ 5till it would
be safer to stick to the rule of 31 characters/ #o not create unnecessaril$ long 1ariable
names as it adds to $our t$ping effort/
ii) The first character in the 1ariable name must be an alphabet or underscore/
iii) @o commas or blanks are allowed within a 1ariable name/
i1) @o special s$mbol other than an underscore can be used in a 1ariable name/
08/-
int mIhraJ
float codeJ
<- C&r%"r7- #un"tin:
clrscr!) function re-uires the header file conio/h i/e Ginclude Dconio/hC
This is used for clearing the output screen i/e console/ 5uppose $ou run a program. alter it
and run it again $ou ma$ find that the pre1ious output is still stuck there itself. at this
time clrscr!)J would clean the pre1ious screen/ 2ne more thing to remember alwa$s use
clrscr!)J after the declaration like
int a.b.cJ
float totalJ
clrscr!)J
=- get"(7- #un"tin:
getch!) function is used to hold the screen in simple language. if u donKt write this the
screen will Lust flash and go awa$/
"
MMCOE, KarveNagar, Pune
>- print#7- an' %"an#7- #un"tin%:
a- %"an#7- #un"tin:
scanf format string !which stands for Mscan formattedM) refers to a control parameter
used b$ a class of functions t$picall$ associated with some t$pes of programming
languages/ The format string specifies a method for reading a string into an arbitrar$
number of 1aried data t$pe parameter!s)/ The input string is b$ default read from the
standard input. but 1ariants e8ist that read the input from other sources/
The scanf function. which is found in C. reads input for numbers and other data-
t$pes from standard input !often a command line interface or similar kind of a te8t user
interface)/The following shows code in C that reads a 1ariable number of unformatted
decimal integers from the console and prints out each of them on a separate line4
Ginclude Dstdio/hC

int
main!1oid)
N
int nJ
while !scanf!MOdM. , n) C E)
printf!MOdPnM. n)J
return EJ
Q
After being processed b$ the program abo1e. a mess$ list of integers such as
"% 123 ')* "% 12
"% 1
23')
will appear neatl$ as4
"%
123
')*
"%
12
"%
1
23')
The scanf!) function also uses the format specifiers/ 5ome of the most commonl$ used
format-specifiers are follows4
Od 4 5can an integer as a signed decimal number/
Oi 4 5can an integer as a signed number/ 5imilar to Od. but interprets the number
as he8adecimal when preceded b$ E8 and octal when preceded b$ E/ For e8ample.
the string E31 would be read as 31 using Od. and 2" using Oi/ The flag h in Ohi
indicates con1ersion to a short and hh con1ersion to a char/
%
MMCOE, KarveNagar, Pune
Ou 4 5can for decimal unsigned int !@ote that in the C** standard the input 1alue
minus sign is optional. so if a negati1e number is read. no errors will arise and the
result will be the twoKs complement. effecti1el$ ignoring the negati1e sign in most
cases/
Of 4 5can a floating-point number in normal !fi8ed-point) notation/
Og. O( 4 5can a floating-point number in either normal or e8ponential notation/
Og uses lower-case letters and O( uses upper-case/
O8. OR 4 5can an integer as an unsigned he8adecimal number/
Oo 4 5can an integer as an octal number/
Os 4 5can a character string/ The scan terminates at whitespace/ A null character
is stored at the end of the string. which means that the buffer supplied must be at
least one character longer than the specified input length/
Oc 4 5can a character !char)/ @o null character is added/
!space)4 5pace scans for whitespace characters/
Olf 4 5can as a double floating-point number/
O<f 4 5can as a long double floating-point number
$- print#7- #un"tin:
i) printf displa$s information on screen/
ii) printf returns the number of characters printed/
iii) printf displa$s the te8t $ou put inside the double -uotes/
i1) printf re-uires the backslash character - an escape se-uence - to displa$ some special
characters/
1) printf can displa$ 1ariables b$ using the O con1ersion character/
1i) printf format4 a string argument followed b$ an$ additional arguments.
A4GORIT+M:
Step1: 7nitiali6e firstIno. secondIno. thirdIno. fourthIno. fifthIno to 6ero/
Step.: Take firstIno. secondIno. thirdIno. fourthIno. fifthIno/ !enter all numbers are in
ascending order/)
Step5: Print firstIno. secondIno. thirdIno. fourthIno. fifthIno/
Step6: stop/
'
MMCOE, KarveNagar, Pune
/4OWC+ART:
CONC4USION:
B$ using Algorithms , flowcharts we can easil$ de1elop the logic of the program and
implement it in the form of the actual programming instructions/
)
Start
Rea'
input 'ata
Write
utput
'ata
Stp

You might also like