Pronic Number in JAVA
Pronic Number
Pronic Number : A number is said to be Pronic number if the product of any two consecutive integer is equal to the number itself.
Example:
Input : 6
: 2 X 3 = 6
Output : It is a Pronic Number
Input : 20
: 4 X 5 = 20
Output : It is a Pronic Number
Input : 8
: 2 X 4 = 8
Output : It is not a Pronic Number
Some Pronic Numbers are :-
0, 2, 6, 12, 20, 30, 42, 56, 72, 90 etc.
Algorithm and Program given below :-
Algorithm :-
- Input number say ‘n’
- Start loop from 1 to less than ‘n’
- If (i*(i+1)==n) then make k=1 and use break statement
- Now check if k==1 then display "It is Pronic Number"
- Else display “It is not Pronic Number”
- Compile and run the program
Program :-
import java.io.*;
import java.util.*;
class Pronic
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int n,i,k=0;
System.out.println("Enter Number");
n= in.nextInt();
for(i=1;i<n;i++)
{
if(i*(i+1)==n) // checking product of two consecutive integer is equal to number or not
{
k=1;
break;
}
}
if(k==1||n==0)
{
System.out.println("It is a Pronic Number : "+n);
}
else
{
System.out.println("It is not a Pronic Number : "+n);
}
}// end of main
}//end of class
Checkout Video of this Program : Click Here
All the Best :)
Keep Learning :)
Comments
Post a Comment