Computer Science, asked by nik7683, 10 months ago

Write a program to input a number and check and print whether it is a pronic number or not. (pronic number is the number which is the product of two consecutive integers)example:-12=3×4,20=4×5,42=6×7.​

Answers

Answered by akshayamca14
17

Answer:

import java.util.Scanner;

public class Example13 {

   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;

               break;

           }

       }

         

       if(ans == 1)

           System.out.println("Pronic Number.");

       else

           System.out.println("Not a Pronic Number.");      

   }

}

Explanation:

Answered by ramasareverma99
7

import java.util.Scanner;

public class CheckPronicNumber

{

public static void main(String args[])

{

// create object of scanner class

Scanner sc = new Scanner(System.in);

// enter the number here.

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;

}

}

// check here for Pronic number.

if(flag == 1)

System.out.println(n+" is a Pronic Number.");

else

System.out.println(n+" is not a Pronic Number.");

}

}

Similar questions