KnowledgeBoat Logo

Computer Applications

Write a program to display all Pronic numbers in the range from 1 to n.
Hint: A Pronic number is a number which is the product of two consecutive numbers in the form of n * (n + 1).
For example;
2, 6, 12, 20, 30,………..are Pronic numbers.

Java

Java Iterative Stmts

ICSE

9 Likes

Answer

import java.util.Scanner;

public class KboatPronicNumber
{
    public static void main(String args[])  {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int n = in.nextInt();
        
        System.out.println("Pronic numbers from 1 to " + n + " :");
        
        for (int i = 1; i <= n; i++) {
            for(int j = 1; j <= i-1; j++)   {
                if (j * (j + 1) == i) { 
                    System.out.print(i + " ");
                    break;
                }
            }
        }
    }
}

Output

BlueJ output of Write a program to display all Pronic numbers in the range from 1 to n. Hint: A Pronic number is a number which is the product of two consecutive numbers in the form of n * (n + 1). For example; 2, 6, 12, 20, 30,………..are Pronic numbers.

Answered By

4 Likes


Related Questions