Page 440 - Cs_withBlue_J_C11_Flipbook
P. 440

Step 7:  Increase i by 1.
              Step 8:  Display fact.

              Step 9:  Stop.
              Problem 5: Write an algorithm to print the highest common factor of two numbers.

              Step 1:  Start.
              Step 2:  Initialise variable gcd and i to 1.
              Step 3:  Input two numbers in num1 and num2.
              Step 4:  Repeat Step 5 to Step 6 while i <= num1 and i <= num2.

              Step 5:  If num1 % i == 0 and num2 % i == 0 then assign gcd = i.
              Step 6:  Increment variable i by 1.

              Step 7:  Print gcd.
              Step 8:  Stop.
              Problem 6: Write an algorithm to check if a number is prime number or not. A prime number is a number which is
              only divisible by 1 and itself. First 10 prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29.

              Step 1:  Start.
              Step 2:  Initialise variables count to 0, and i to 1.
              Step 3:  Read number num.

              Step 4:  Repeat Step 5 to Step 7 while i <= num.
              Step 5:  If num is divisible by i then go to Step 6, else go to Step 7.
              Step 6:   Increment count by 1.
              Step 7:  Increment i by 1.

              Step 8:  If count = 2 then go to Step 9, else go to Step 10.
              Step 9:  Display num “is a prime number”, and go to Step 11.
              Step 10: Display num “is not a prime number”.

              Step 11: Stop.
              Problem 7: Write an algorithm to print the first 10 terms of a Fibonacci series. A Fibonacci series is a series in which
              any term is the sum of its previous two terms. The first two terms are 0 and 1. The first ten terms of a Fibonacci
              series are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34.
              Step 1:  Start.
              Step 2:  Initialise variables term1 to 0, term2 to 1, term3 to 0 and i to 1.

              Step 3:  Read the number of terms in num.
              Step 4:   Display term1 and term2.

              Step 5:  Repeat Step 6 to Step 9 while i <= num -2.
              Step 5:  Calculate term3 = term1 + term2.

              Step 6:  Display term3.
              Step 7:  Initialise term1 = term2.

              Step 8:  Initialise term2 = term3



                438438  Touchpad Computer Science-XI
   435   436   437   438   439   440   441   442   443   444   445