Computer Science, asked by allmyccnt, 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.]
Examples:
12 = 3 * 4
20 = 4 * 5
42 = 6 * 7

Answers

Answered by kaanhasinghbaby
7

Answer:

import java.util.*;

class pronic

{

public static void main()

{

int n,i=1,p=0;

Scanner sc=new Scanner(System.in);

System.out.println("Enter a number");

n=sc.nextInt();

while(p<n)

{

p=i*i+1;

if(p==n)

{System.out.println("pronic");

break;

}//while loop ending

else if (p<n)

{System.out.println("not");

break;

}//else if ending

else

{

i++;

}//else end

}//if loop ending

}//main end

}//class end

Explanation:

At first we will input a no. from the user and  start a while loop in which we will compare a variable p with value 0 to the input no. and then we will start multiplying two consecutive no. as i*i+1 and store it in p and if p comes equal to input no. the no.is  pronic else if p>n it is not and in an else condition we will increase i by 1

Similar questions