sm oopd2 [flow charts 2]

Upload: ashish-chopra

Post on 03-Jun-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Sm Oopd2 [Flow Charts 2]

    1/12

    FLOW CHARTS

    It is a chart showing flow of logic involved in solvingthe problem.It is defined for an algorithm.It can also be defined as the diagrammaticrepresentation of an algorithm.It is also defined as a visual or graphical representationof an algorithm.

    It is easy to understand and analyze the problem.It is an useful aid for programmers and system analysts.It is machine independent. They can be used for anytype of logic

  • 8/12/2019 Sm Oopd2 [Flow Charts 2]

    2/12

    Symbols used in Flowcharts

    Name Symbol Function

    TerminalTo indicate begin and end in a flowchart

    Input/output Input or output data or information

    Processing Calculations, data manipulation orinformation processing

    LoopingProcesses a group of instructionsrepeatedly

    Decision A comparison or decision which leads theflow of control to take alternate paths

    Predefined

    process

    Group of operations not listed in the particular flowchart

    Connector An entry from or an exit to another part ina flowchart

    Flow Direction Represents the direction of flow of control

  • 8/12/2019 Sm Oopd2 [Flow Charts 2]

    3/12

    Start

    Read A, B, C

    A>B

    A>C B>C

    Print A Print CPrint B Print C

    Stop

    Flowchart to find the largest of 3 numbers

  • 8/12/2019 Sm Oopd2 [Flow Charts 2]

    4/12

    Q Show using flowchart how to find the average height of boys and average heightof girls in the class.

    Ans:

    t_b_h total boys height

    t_g_h total girls height

    t_b total no of boys

    t_g total no of girls

    a_v_b average height of boys

    a_v_g average height of girls

    n total no of students

    n1 no of boys and girls after each iteration

    code=0 (for girl)

    code=1 (for boy)

  • 8/12/2019 Sm Oopd2 [Flow Charts 2]

    5/12

    start

    read roll no , code , height

    t_b_h 0t_b 0

    t_g_h 0t_g 0n 10

    a_v_g 0a_v_b 0

    n1 0

    code =1

    t_b_h t_b_h + heightt_b t_b + 1n1 n1 + 1

    t_g_h t_g_h + heightt_g t_g +1n1 n1+1

    A

    B

    Y N

  • 8/12/2019 Sm Oopd2 [Flow Charts 2]

    6/12

    A

    n1=nB

    a_v_b t_b_h / t_b

    a_v_g t_g_h / t_g

    Print a_v_b , a_v_g

    Stop

  • 8/12/2019 Sm Oopd2 [Flow Charts 2]

    7/12

    To find largestof n numbersusing 2 memorylocations num1and num2

    Read n , num1

    Start

    repeat till 4 ,till n = 1

    read num2

    num1 num2num2>num1

    n n-1

    Print num1

    stop

    4

  • 8/12/2019 Sm Oopd2 [Flow Charts 2]

    8/12

    Q) Draw a flowchart to count the number of non-zero numbers in aseries of 10 numbers. Start

    nzd 0,i=1

    repeat till 4 ,till i=11

    enter d

    d=0 nzd nzd + 1

    i i+1

    Print nzd

    stop

    4

  • 8/12/2019 Sm Oopd2 [Flow Charts 2]

    9/12

  • 8/12/2019 Sm Oopd2 [Flow Charts 2]

    10/12

    Draw a flowchart to find the sum of the first 50natural numbers

  • 8/12/2019 Sm Oopd2 [Flow Charts 2]

    11/12

    Draw a flowchart for computing factorial of N

  • 8/12/2019 Sm Oopd2 [Flow Charts 2]

    12/12

    EXERCISESWrite an algorithm and draw a flow chart for the following problems 1. Read a number N and print all its divisors.2. Compute the sum of the digits of any given number3. Find the sum of given N numbers.4. Sum of squares of integers from 1 to 505. Print the Message Hello on the Screen. 6. Display a Triangle of * on the screen.7. Perform the different arithmetic Operations.

    8. Evaluate the area of the circle Area = Pi * R*R9. Convert the time in seconds to hours, minutes and seconds. (1 hr =3600 sec).10. Find the sum of the digits of a four-digit number (ex 1234 sum=10).11. Convert temperature given in Fahrenheit to Centigrade and Centigrade to

    Fahrenheit (C=5/9(F-32)).

    12. Converting distance in mm to cm, inch, feet (1 cm =10mm, 1inch=2.5cm, 1 feet=12 inches).13. Compute n th Fibonacci no.14. Generate Fibonacci series up to n.15. Covert binary number to decimal.16. Convert decimal number (Positive) to binary.