0% found this document useful (0 votes)
38 views25 pages

DS Computer Science

The document provides an overview of algorithms, including their definitions, representations, and examples. It explains different ways to express algorithms such as step form, pseudo-code, and flowcharts, highlighting their respective structures and purposes. Additionally, it discusses programming language structures, tokens, keywords, and constants in C programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
38 views25 pages

DS Computer Science

The document provides an overview of algorithms, including their definitions, representations, and examples. It explains different ways to express algorithms such as step form, pseudo-code, and flowcharts, highlighting their respective structures and purposes. Additionally, it discusses programming language structures, tokens, keywords, and constants in C programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Se ge what is alqorthm what ave the alqovithm dessq) =ning tools 1 Explain arth Examples \ | | Plgorithms «- AG algorithm 16 a st ep- by- step Process, to Had the Solution to 4 particular problem » ina | -fanite Qumbes ot Step. | Bitternt ways of stoting alqovithms :- Algorithms | can be expressed tn several ways i depending ©n | the purpose and the audrence - fete ate the most | Common ways of stating algorithms. | » step- form | 3 pseudo -Code Flowchart } |Step-torm + Step-toxm of algotithm ie the simplest | and consist? of a sequence oF numbered stepo. | The Step form uses just novmoh language to det | L-ne each procedure Every statement , that dete a3 actton ,%6 logically velated ‘to the preceding statement: wate a step torm Calqorithm)in add tio numbers | enteied by the uset \ Step! .- Start £ i; | step. Beclaie vartable num! um? and sum | 8eP3 tb Read values num! and Numt ‘ | Step4 > Add numi and num 2 and’aserq” Abe vesu { 4 | to sum: Sums aumitnum 2 | | Step5 = Pisplay gum | gtepG + Stop. | pseudo codes pseudo code 16a human -readable, qntormal :way to describe “the step of an algorith =m 61 programming logic .ustng Plan lanquage land basic programming constructs. Tt's not meant | tobe executed by a Computer ,but rather to help | Progtammes plan and understand the stiuctute ot la Program petore wrsting the actual code ina | Specie Programming lanquage. | Example + Waite a paeudo code totind the sum ot | \ Numbers. | Step | + BEGIN | Gtepa ¢- DECLARE fumt snum2, gum | gteps © INpur" Enter the trret Number | 7 Oum! Step 4 = INpoT “ Enter the Second Number ,"num 2 step 5 :- SUM = OuMitnume corse gel | Step 6 = ourpuT Ihe sum 15) gum | gtept i END. ' Flow chart Flowchart #3 0 graphical represen tats Zon of a Igorithm: They use symbob av10w 3, -on of an a tectanglekar, diamond sete ~~ to represent Sequen _ce, dicrsion and vepetitron acttons. common Flowcharts symbol - [sane | Name [ ~ Fun ctton. 5 | Start End tndtcateg the start or end Cc J) / | pornt of the process. | | (process | Besctthe® @ specific actton | \ {| or task tp be pertormed vntthi | a __Fin the procese i| Pecrsion | penotes a question OT Condr | | | |-tron to be evaluated - Also, | | .» the Pitterent output options | | ___| based on the anewet- \ |connectoi | used to connect ditterent | {| ( | es ot the diagram that | Jane — | ahh harete Plncels | | Flow | It teptesents the directions | nN | AtVOW | oF the process How 1 1otesac |) fecnpsct |-ting the order to which | | lactton are cartied out: “| Thpat foutput! re tothe material of data | ot Jentering 01 leaving the Sysicm| Sy mbo! Name _ “Functton. ries) | | Pecument om . “y [Reters tp an external — document or tle. ; shaaitt "—Tyndteate derval prmied ee @ Prepatatin| Marks an adjustment to ano | — ~ther step tn the process | Piow a How chatt to accept two Numbers, =a tind the sum ot too oumbers- | | | | al explain | jn detar! the structure of a ¢ Lanquage? 1 13a stucted programming Janquage Every ‘Cc’ \ program has the followin 4 qeneral otvuctute. __PocuMentattoN section | Link gection (Header tiles aectton) Rettnation section Globo! Peclarations main() Functron sectton | Z pecleration parti Frecution part; “program section Function | _ Function » t(uger detined™ +tunctfons | | | Function a | \ | | pocumentatton section :- This gectton consists of a | eo ee | get of Comment lines giving the name ot the pro} '_avam , which the programmer would like to Use Later - The comment lines are ¥4nored. by the | ‘compiler than’ means they are not executed -In | Le, there are two typed of Comments. | | Datngle Line comments ‘- Single line comment begins) feseenanareraac a { 4 [cot Af lyrabals we Can wine any oumber S Walphe Hines Conmnends 100 pq rome: aingle lex ' 1009 CO 4 > >mulltple Lroes congments (Multiple (1009 Coro i Lhe qin wrth Agymbel and nds worth 4/9 CA0 | corte any Murobed of roulliple [hed Comments 1046 | prequam | ADU be corament toes Wa © programe Tust | Plovides the qutdeltnens to understand the | P¥oqvam and si% Code | Cy j Ft Hustle a proquam to print a message | Link declton Link section Contains pre -procesoct coramands and ‘these commands at@ used to tnclud -e header tileg. we use the # include Statement [0 include the header file (nto out proqram. | Fut include <6tdioh>. | “4 " Detination Bectton: The detznatton Zection detin —e® all symbolic constants. civ deine pL 3-l4l >Here pr tgs the symbolic constant Global Peclaratton section + [Re global declarate —9 #6 used to detrne the global Vatiables, luohich are common for all the tuncttons after | "ts declaration we oso use the qlobal declarats \~on tv declare functtons. | marn_( function sectiod :- Every © plogram muse | have one main ( )tunctiron -It 78 the Starting pont toy proqvam execution -[hre sectron Contains | two parts 1 Peclaration ancl executable parts: | These two parts must be to between opening () | and closzng braces (3). | The declaratton part ceclaves all the vatrables | and -functtons , whtch ate to be used fn the executable part. betore the | = the declarvatton pait must be sng all! executable part -Frecutable part conta’ the tostructtons, to be ekecuted Treading dato idisplaytng the result :Calculatvo }—ng rete---J- => fhe program exe cution begins at the opening brace and ends at the closing brace. |All the statements the declayatson and | | executable parts end with a semicolon. | | ieee | \ | wo a | Gub - prog ramming Sections The subproqiam sect ton contain all the uset- defroed +unc tron that ate called in the main tunction. Uset dletened functions are generally placed tromedts —ately attet the main -tunction 1 although they may appear in any order - pli the section rexpect main function May be absent when they are not requited- ly main te the unique Section of the proqtam | s-e, use OF more than one MaiN( ) 15 Not | allowed - ) what 13 token Explain types of tokens tn c kanqu \ | Tre Smallest tndtvrdual untt 6 called token. | In c-progtamming tokens ave basic building | blocks - C Supports the $4 : | they ee Pp x type of tokend- | Keywords + Keywords are pre delined o4 tebe’ j-ed words used in proqramininy that bave spec |-tal meantng These meaning of the Keyuootds ba} liao alyeady been deocttbed to the ¢ Compiler. | | These meaning cannot be changed | | => Thus 1 the keywords cannot be used as Variable | | names because that would ty to change. the | existing meaning of dhe keyword which 15 rt || allowed. | = keywords are always entered tM lower Case | lettet9 «Keywords are part of the syntax ond | they cannot be used 08 20 tdeotrtrer- | = c hanquage has teserved 32 woids a8 key worda | they ase- ---- | | auto pieak caee char = const | do double el8¢ = enum — et tein | qoto it int 104 reqisted } signed siteot state struct = gunrtch anerqned Vord —volatrle while cletault ghort continue float tetuia «type det fot union : \ | | Constant + constant nc refer to tered value | —— | that donot change durin4 the eLeustton of ja Progorm

You might also like