0% found this document useful (0 votes)
121 views10 pages

CP GTU Study Material E-Notes Unit-1 04122020055611AM

Uploaded by

Love Shah
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)
121 views10 pages

CP GTU Study Material E-Notes Unit-1 04122020055611AM

Uploaded by

Love Shah
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
You are on page 1/ 10
H Darsha Unit-1 Flowchart & Algorithm Inmeofou die Open Snee 1. What is Algor Compare them. 1m? What is Flowchart? Write down the advantages and disadvantages. Purpose of Flowchart and Algorithm in Programming: ‘© Programming is nothing but describing the steps needed to be executed by the computer to solve any problem or task. ‘+ Say for example we had all seen food recipes to prepare any food. Same like in our Computer Programming the word recipes will be replaced by the procedure and the ingredients are called input/s, computer will follow the procedure with the given input/s data and what we final achieved that is known as output. Algorithm ‘* An algorithm is a step by step procedure for solving a problem ina finite number of steps. ‘© tis written in the natural languages like English. > Advantages: © Easy to write, ‘© To understand it, simple read the algorithm. Itis not dependent on any programming languages. Every steps has its own logical meaning and then it follows the next step. Algorithms for big problems can be divided in to small parts. Disadvantages: Difficult to debug. Time Consuming Difficult to show branching and looping, ery 6 ‘© Jumping (goto) makes it hard to trace some problems. ‘Types of Algorithm, Recursive Algorithm, . 1 2. Dynamic Programming Algorithm 3. Backtracking Algorithm 4. Divide and Conquer Algorithm, 5. Greedy Algorithm 6. Brute force Algorithm 7. Randomized Algorithm > Example: Write algorithm to find out the area of circle. Step 1: Start Step 2: Initialize PIC3.14, area €0 Step 3: Read value of r Step 4: Calculate area € PI * rr Step 5: Print area Step 6: Stop i] DEP: ce cP (3310701) Prof. Akash N. Siddhpura H Darsha Unit-1 Flowchart & Algorithm Inmet a epee Flowchart Flowchart is a pictorial or graphical representation of a process. ‘© Each step in the process is represented by a different symbol and contains a short description of the process. ‘The flow chart symbols are linked together with arrows showing the process flow direction, This pictorial representation can give step-by-step solution of the given problem, Advantages: Easy to draw. Easy to understand logic. Easy to identify mistakes by non-technical person. ‘© Easy to show branching and looping. Disadvantages: Time consuming Difficult to modify Very difficult to draw flowchart for big or complex problems, oe sey Have to use special symbol for each and every task. Characteristic of Flowchart: Must use standardized Symbols ‘Symbols should be correct and as per the flowchart rules Should contains clear, short and readable statements in symbols Must be clear starting and ending point . Must contains clear arrows for conversion from one step to another step > Example: Start ¥ Initialize Area €0, Plead 7 ReadValueofr —/” Calculate Area € Plt 2] DEP: CE cP (3310701) Prof. Akash N. Siddhpura & Darshan arsha Inmet a epee Unit-1 Flowchart & Algorithm Comparison: Flowchart Algorithm, Itis a pictorial representation of a process. Itis step wise analysis of the work to be done. Solution is shown in graphical format. Easy to understand as compared to algorithm, Solution is shown in natural language like English Itis somewhat difficult to understand. Easy to show branching and looping. Difficult to show branching and looping, Flowchart for big problem is impractical ‘Algorithm can be written for any problem 2. Explain various symbol used in flowchart. oO LT <> O t — Arrows Decision making, Connector {An oval represents to start or end of the Start / Stop flowchart. Input / Output A parallelogram represents input or output, (Read / Print) A rectangle represents a process Process ‘A diamond indicates a decision. When ‘there are two paths , user have to choose one path with ans YES or NO, at that this symbol is used Indicates that the flow continues where a ‘matching symbol has been placed. Aline is a connector that shows relationships between the representative shapes. 3. Write an algorithm and Draw Flowchart to find whether given number is even or odd. Algorithm: Step1: Start Step2: Input no. Step3: Ifno mod 2=0, goto 5. Step 4: Print given no is even, goto 6. Step 5: Print given no is odd. Step 6: Stop. 3] DEP: cE cP (3310701) Prof. Akash N. Siddhpura H Darshan Unit-1 Flowchart & Algorithm Inmet a epee Flowchart: Yes Is Nomod 207 Write an algorithm and Draw Flowchart to find maximum number from a given 2 numbers Algorithm:~ Step1: Start Step2: Read a,b Step3: Ifa>b, gotoS Step4: Print b is maximum, go to 6 Step: Printa is maximum. Step6: Stop Flowchart: Start /_Readab / Print bis Print ais, maximum C= a] DEP: cE cP (3310701) Prof. Akash N. Siddhpura H Darshan Unit-1 Flowchart & Algorithm Inmet a epee 5. Write an algorithm and Draw Flowchart to print maximum number from a given 3 numbers. Algorithm:- Step1: Start Step2: Reada,b, c Step3: Ifa>b, goto7 Step4: lac, goto Step 5: Print is maximum, go to 10 Step 6: Print cis maximum, go to 10 Step7: If b>c, goto9 Step8: Print b is maximum, goto 10 Step9: Print cis maximum. Step 10: Stop Flowchart: S| DEP:CE cP (3310701) Prof. Akash N. Siddhpura H Darshan Unit-1 Flowchart & Algorithm Inmet a epee Write an algorithm and Draw Flowchart to print 1 to N numbers. Algorithm: Step1: Start Step2: Initialize count © 1 Step3: Read N Step 4: Print count Step 5: Increment count by 1, count € count +1 Step6: If count>N, goto4 Step7: Stop Flowchart: Initialize count € 4 /feadn / Print count Increment count by 1 count € count +1 count > N?? Yes, top 6 DEP:cE cP (3310701) Prof. Akash N. Siddhpura H Darshan Unit-1 Flowchart & Algorithm Inmet a epee Write an algorithm and Draw a flowchart to print ODD numbers between 1 to N. Algorithm: Step: Start Step 2: Initialize count € 1 Step3: Read N Step 4: Print count Step 5: Increment count by 2, count € count +2 Step6: If count>N, goto4 Step7: Stop Flowchart: Start Initialize count © 1 Read N Increment count by 2 count € count +2 Yes 7 DEP: CE cP (3310701) Prof. Akash N. Siddhpura H Darshan Unit-1 Flowchart & Algorithm Inmeofou die Open Snee Write an algorithm and Draw a flowchart to print addition of ODD numbers between 1 to N. Algorithm: Step1: Start Step 2: Initialize count €1, sum €0 Step3: Readno Step4: Calculate sum € sum + count Step 5: — Increment count by 2, count€count+2 Step6: Ifcount > no, goto 4. Step 7: Printsum Step 8: — Stop. Flowchart: Start + Initialize sum €0, ‘count € 1 7 fead Value ofne 7 + | Calculate sum € sum + count + Increment count € count +2 count > no? YES Print sum 8] DEP:cE cP (3310701) Prof. Akash N. Siddhpura DH Darshan | Unit-1 Flowchart & Algorithm Inmet a epee Write an algorithm and Draw Flowchart to find the factorial of a given number. Algorithm:- Step1: Start Step2: Initialize count€1 fact1 Step3: Readno Step 4: Calculate fact€fact * count. Step 5: — Increment count by 1, count€count+1. Step 6: If count > no, goto 4. Step7: Print fact. Step8: Stop. Flowchart: Initialize fact €1, count € 1 Read Value of no ol Calculate fact€ fact * count I Increment count € count + 1 No YES ‘| DEP:cE cP (3310701) Prof. Akash N. Siddhpura H Darshan Unit-1 Flowchart & Algorithm Inmeofou die Open Snee 10. Write an algorithm to swap value of two variables. Algorithm: Step: Start Step2: Initialize a€ 0, bE 0, c&0 Step3: Read Value of a, b Step4: Print value of a, b Step: Givevalue of atoc,cfa Step6: Givevalue of btoa,a€b Step7: Give value of ctob,b€c Step8: Print value of a, b Step9: Stop. 11. Application of C language. ‘© Used for creating computer applications. ‘* Used in writing embedded softwares. ‘© Used for developing testing softwares & simulators. '* Used to implement different operating system operations. 10] DEP: cE cP (3310701) Prof. Akash N. Siddhpura

You might also like