Page 46 - iPro_trackGPT_V5_Class8
P. 46

Flowchart:                                         Example 6:  Write  an  algorithm  and  draw  a
                                                                                  flowchart to check whether a given
                                Start                                             number is even or odd.
                                                                     Algorithm

                                                                     Step 1:  Start.
                              Read n                                 Step 2:  Read the number n.
                                                                     Step 3:  Check If n % 2 == 0, then
                                                                               print "Number is Even."

                               i = 1                                           Else
                              fact = 1                                         print "Number is Odd."
                                                                     Step 4:  Stop.

                                                                     Flowchart:
                                 Is
                                               No
                              i < = n?                                                     Start




                                    Yes                                                   Read n

                            fact = fact*i
                                                   Print fact


                                                                                            Is
                              i = i + 1                                                  n%2==0


                                                                            Yes                             No

                                Stop
                                                                        Print "Number is         Print "Number is
                                                                              Even."                   Odd."






                                                                                           Stop








                        A program is a set of instructions written in a language called a programming language.
                        An algorithm is a sequence of steps designed to solve a problem or complete a task.
                        Writing an algorithm is an essential step in problem-solving and programming because
                       it helps in planning and visualising the solution before it is implemented in code.

                        A flowchart is a type of diagram that visually represents an algorithm or process.




                    44    TrackGPT iPRO (V5.0)-VIII
   41   42   43   44   45   46   47   48   49   50   51