Write a program to input a number and check and print whether it is a 'Pronic' number or not.
Use a function int Pronic() to accept a number. The function returns 1, if the number is 'Pronic',
otherwise returns zero 0.
(Hint: Pronic number is the number which is the product of two consecutive integers)
import java.util.Scanner;
public class PronicNumber
{
public static ______________ pronic() {
int isPronic = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter the number to check: ");
int n = in.nextInt();
for (int i = 1; i <= n - 1; i++) {
if (i * _______________== n) {
isPronic = 1;
break;
}
}
____________ isPronic;
}
public static void main() {
int __________ = pronic();
if (r == 1)
System.out.println( "Number is a pronic number");
else
System.out.println( "Number is not a pronic number");
}
}
Answers
Answered by
3
I DON'T KNOW THIS SOLUTION
Answered by
1
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.");
}
}
Similar questions