# Python Program to find Composite Number

Last Updated:

## What is Composite Number?

A positive integer that has at least one divisor other than 1 and itself.

Tips: It is recommended to use our online Composite Numbers calculator for better understanding.

## Examples

The following table provides few examples of composite numbers.

NumberDivisorResult
13 1, 13 Not a Composite Number
15 1, 3, 5, 15 Composite Number
47 1, 47 Not a Composite Number

## Using for loop

In the following example, we will check whether the number 12 is a Composite number or not using for loop.

### Example

Python Compiler
num = 12; count = 0; for i in range(1, num+1): if(num % i == 0): count += 1; if(count > 2): print("%d is a composite number" % num) else: print("%d is not a composite number" % num)

## Using while loop

In the following example, we will check whether the number 12 is a Composite number or not using while loop.

### Example

Python Compiler
num = 12; count = 0; i = 1; while(num >= i): if(num % i == 0): count += 1 i += 1 if(count > 2): print("%d is a composite number" % num) else: print("%d is not a composite number" % num)

## Composite Numbers between the Given Range

In the following example, we will find all the Composite numbers between 1 and 10.

### Example

Python Compiler
start = 1; end = 10; count = 0; print("Composite Numbers between %d and %d: " % (start, end)); for start in range(start, end+1): for i in range(1, start+1): if(start % i == 0): count += 1; if(count > 2): print(start, end=" ") count = 0

## Check Whether the Given Number is Prime or Composite

In the following example, we will check whether the given number is a Prime number or Composite number.

### Example

Python Compiler
num = int(input("Enter a (int) number: ")); count = 0; for i in range(1, num+1): if(num % i == 0): count += 1; if(count > 2): print("%d is a composite number" % num) else: print("%d is a prime number" % num)