Thursday 17 August 2017

Find it is PRONIC NUMBER or not

pronic number:
pronic number is a number which is the product of two consecutive integers, that is, a number of the form n(n + 1). The study of these numbers dates back to Aristotle. They are also called oblong numbersheteromecic numbers, or rectangular numbers; however, the "rectangular number" name has also been applied to the composite numbers.
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 



/* program to find given number is pronic number or  not*/

import java.util.*;
class PronicNumber
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
       
        System.out.print("Enter a number : ");
        int n = sc.nextInt();
        int flag = 0;
   
        for(int i=0; i<n; i++)
        {
            if(i*(i+1) == n)
            {
                flag = 1;
                break;
            }
        }
       
        if(flag == 1)
            System.out.println(n+" is a Pronic Number.");
        else
            System.out.println(n+" is not a Pronic Number.");    
    }
}


OUTPUT:

Enter a number : 420
420 is a Pronic Number.
 
Enter a number : 13
13 is not a Pronic Number.
 
Enter a number : 12
12 is a Pronic Number.
 
Enter a number : 21
21 is not a Pronic Number

No comments:

Post a Comment