Pronic Number - Coder's point

Saturday, March 16, 2019

Pronic Number

A pronic number is anumber which is the product of two consecutive integers, that is,a  number of the form n(n + 1).                                                                                               
 import java.util.*;  
 class pronic_number  
 {  
   public static void main()  
   {  
     Scanner in = new Scanner(System.in);  
     System.out.println("Enter any number");  
     int num=in.nextInt();  
     int flag=0;  
     int i=0;  
     while(i<=num)  
     {  
       if(i*(i+1)==num)  
       {  
         flag=1;  
         break;  
       }  
       i++;  
     }  
     if(flag==1)  
     {  
       System.out.println("pronic number");   
     }  
     else  
     {  
       System.out.println("Not a pronic number");  
     }  
   }  
 }  
Output:
Enter any number
6
pronic number

No comments:

Post a Comment