Pronic Number

Back to Programming

Description

A number is said to be a pronic number if the number is the product of two consecutive integer numbers.

For example, if we consider a number 72, it is the product of two consecutive integers 8 and 9. Therefore, 72 is a pronic number.

Now, if we consider a number 16, it is the product of 2 and 8 or 4 and 4 but no one is the consecutive integers. Therefore, 16 is not a pronic number.

For this program, first, the number is taken as input. A loop is executed from 1 to half of the number and if the number is the product of any two consecutive numbers then the number is a pronic number otherwise not.

Algorithm

``````INPUT: A number
OUTPUT: Whether it is a pronic number or not
PROCESS:
Step 1: [Taking the input]
Read n [The number to be checked]
Step 2: [Checking for pronic number]
For i=1 to n/2 repeat
If i×(i+1)=n then
Print "The given number is a pronic number"
[End of ‘if’]
[End of ‘for’ loop]
[If the number is not a pronic number]
If i>n/2+1
Print "The given number is not a pronic number"
[End of ‘if’]
Step 3: Stop.
``````

Time Complexity:

for(i=0;i<=n/2;i++)------------------------------------O(n)

{

if(i*(i+1)==n)-------------------------------O(1)

printf("The given number is a pronic number");

}

//if the number is not a pronic number

if(i>n/2+1)-----------------------------------------------O(1)

printf("The given number is not a pronic number");

The time complexity of this program is O(n) where ‘n’ is the given number.

Space Complexity:

The space complexity of this program is O(1) as it requires a constant number of memory spaces to execute the program for any given input.