Pronic Number : A Pronic number, oblong number, rectangular number or Heteromecic number, is a number which is the product of two consecutive integers, that is, n (n + 1).
The first few Pronic numbers are:
0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462 … etc.
Code-1: Using Pure Function ( Return):
import java.util.*;
class Pronic_Number
{
public int func ( int n )
{
int i,f=0;
for( i=1; i<=n; i++)
{
if ( i * ( i + 1 ) ==n )
{
f=1;
break;
}
}
return f;
}
public static void main ( String args [ ] )
{
int no, p;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number: ");
no=sc.nextInt();
Pronic_Number obj = new Pronic_Number( );
p=obj.func(no);
if(p==1)
{
System.out.println(no + " is a Pronic Number");
}
else
System.out.println(no + " is not a Pronic Number");
}
}
Output:
Enter a number : 20
20 is a Pronic Number.
Enter a number : 73
73 is not a Pronic Number.
The first few Pronic numbers are:
0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462 … etc.
Code-1: Using Pure Function ( Return):
import java.util.*;
class Pronic_Number
{
public int func ( int n )
{
int i,f=0;
for( i=1; i<=n; i++)
{
if ( i * ( i + 1 ) ==n )
{
f=1;
break;
}
}
return f;
}
public static void main ( String args [ ] )
{
int no, p;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number: ");
no=sc.nextInt();
Pronic_Number obj = new Pronic_Number( );
p=obj.func(no);
if(p==1)
{
System.out.println(no + " is a Pronic Number");
}
else
System.out.println(no + " is not a Pronic Number");
}
}
Output:
Enter a number : 20
20 is a Pronic Number.
Enter a number : 73
73 is not a Pronic Number.
No comments:
Post a Comment