Home » ALGORITHM » ALGORITHM AND FLOWCHART FOR COMPOSITE NUMBER

ALGORITHM AND FLOWCHART FOR COMPOSITE NUMBER

Those numbers which are divisible by other than itself and 1 are known as composite numbers. The number 4 can is divisible by 1, 2 and 4 therefore 4 is a composite number. But 7 is divisible by only 1 and 7 thus 7 is not a composite number. For example 8, 6, 9, 25, 102, 502 etc. The smallest composite number is 4. 1, 2 and 3 are not composite numbers. 2 and 3 are prime numbers.

A composite number can also be defined as if a number has factors other 1 and itself then it is a composite number. For example factors of 12 are 1, 2, 3, 4, 6 and 12 thus 12 is a composite number. The factors of a number are those numbers which divide the number completely (leaving no remainder)

ALGORITHM TO CHECK COMPOSITE NUMBER

(Composite Number) Suppose N is a positive Integer. N will be a composite number if it has a factor or factors other than 1 and N. In this algorithm we will divide number N from numbers 2 to N – 1 one by one. If N is divisible by any number from 2 to N – 1 then N will be a composite number. Or we can say if we N has a factor from 2 to N – 1 then N is a composite number.

Step 1: Start

Step 2: [ Take Input ] Read: N

Step 3: [ Initialize Counter ] I = 2 and F = 0

Step 4: Repeat While I < N

                        Check If N%I == 0 Then

                                    Set: F = 1 and Break the Loop

                        [ End of If Structure ]

                        Compute: I = I + 1

            [ End of While Loop ]

Step 5: Check If F == 1 Then

                        Print: N is a composite Number.

            Else

                        Print: N is not a Composite Number.

            [ End of If Else Structure ]

Step 6: Exit

FLOWCHART TO CHECK COMPOSITE NUMBER

The flowchart to check whether a given number is a composite number or not is shown below.

FLOWCHART TO CHECK COMPOSITE NUMBER

ALGORITHM TO GENERATE COMPOSITE NUMBERS

(Generate Composite Numbers) Since the smallest composite number is 4 therefore the Lower Limit (LL) will start from 4 and Upper Limit (UL) will be chosen by the user. If the value stored in LL is a composite number then it will be printed otherwise values stored in LL will be increased by 1. The above process will continue untill LL is not equal to UL.

Step 1: Start

Step 2: [ Take Input For Range ] Read: UL

Step 3: Set: LL = 4

Step 4: Repeat While while LL ≠ UL

                        Step 4a: Set: N = LL, F = 0 and I = 2

                        Step 4b: Repeat While I < N

                                    Check If N%I == 0 Then

                                                Set: F = 1 and Break the Inner while Loop

                                    [ End of If structure ]

                                    Compute: I = I + 1

                        [ End of Inner While Loop ]

                        Step 4c: Ckeck If F == 1 Then

                                    Print: N

                        [ End of If structure ]

                        Step 4d: Compute: LL = LL + 1

            [ End of Outer While Loop ]

Step 5: Exit

FLOWCHART TO GENERATE COMPOSITE NUMBERS

The given below flowchart generates composite numbers with a given range.

FLOWCHART TO GENERATE COMPOSITE NUMBERS

Related Posts

  • ALGORITHM TO CHECK EVEN AND ODD NUMBERSALGORITHM TO CHECK EVEN AND ODD NUMBERS A number is said to be even number if it leaves no remainder when divided by 2. There is an alternative definition of even number and it is as a number having any number from 0, 2, 4, 6 […] Posted in ALGORITHM
  • ALGORITHM AND FLOWCHART FOR COPRIME NUMBERALGORITHM AND FLOWCHART FOR COPRIME NUMBER A Coprime number comes in pair of integers. Thus they are defined as those paired numbers which can be divided by the common number 1 are called coprime numbers. Suppose a and b are two […] Posted in ALGORITHM
  • PERFECT NUMBER ALGORITHM AND FLOWCHARTPERFECT NUMBER ALGORITHM AND FLOWCHART A number is said to be a perfect number if the sum of factors of the number (excluding number itself as a factor) is equal to the number itself. Example of perfect numbers are 6, 28, 496, […] Posted in ALGORITHM
  • ALGORITHM TO FIND FACTORIALALGORITHM TO FIND FACTORIAL The product of positive integers from 1 to N is called factorial N. It can also be defined as The factorial of a number N is defined as the product of first N Natural Numbers. Factorial N […] Posted in ALGORITHM