CHECK WEATHER THE NUMBER IS PRONIC OR NOT || PROGRAM IN JAVA

CHECK WEATHER THE NUMBER IS PRONIC OR NOT || PROGRAM IN JAVA


CHECK WEATHER THE NUMBER IS PRONIC OR NOT

dhiren4.blogspot.com

1.What is a pronic number?
Ans:- product of two consecutive integers as shown in the above figure.

Program


import java.util.Scanner;
public class Pronic
 {

    public static void main(String args[])
       {
        Scanner sc = new Scanner(System.in);
        System.out.print("Input a number : ");
        int num = sc.nextInt();
        int ans = 0;
    
        for(int i=0; i<num; i++)
        {
                            
            if(i*(i+1) == num)
            {
                //ans = 1;
                //System.out.println(" "+i);
                //System.out.println(i+1);
                //break;
            }
        }
         
        if(ans == 1)
            System.out.println("Pronic Number.");
        else
            System.out.println("Not a Pronic Number.");      
    }
}

Output

dhiren4.blogspot.com

Post a Comment

0 Comments