Find out all Pronic numbers present within a given range

A Number is a Pronic number which is the product of two consecutive integers, that is, a number of the form num(num+1).

Example:

               Given Number=90
               product of two consecutive number 9*10=90
               so, 90 is a Pronic Number.
                 
                Given Number=80
               there are no consecutive multiple presents. 
               That's why 80 is not a  Pronic Number.

                                          
Problem statement:-  Program to Find out all Pronic numbers present within a given range.

Data requirement:-

   Input Data:- range1, range2

   Output Data:- i, range1, range2

   Additional Data:- flag, j


Program in C


Here is the source code of the C Program to Find out all Pronic numbers present within a given range.

Code:

//Pronic Number in range
#include<stdio.h>
int main()
{
    int range1,range2,i,j,flag=0;
    printf("Enter a range:");
    scanf("%d %d",&range1,&range2);
    printf("Pronic Numbers between %d and %d are: ",range1,range2);
    for(i=range1;i<=range2;i++)
    {
        flag=0;
     for(j=0;j<=i;j++)
   {
       if(j*(j+1)==i)
       {
           flag=1;
           break;
       }
   }

   if(flag==1)
    printf("%d ",i);
}
}

Input/Output:
Enter a range:1
100
Pronic Numbers between 1 and 100 are: 2 6 12 20 30 42 56 72 90

Program in C++

Here is the source code of the C++ Program to Find out all Pronic numbers present within a given range.

Code:

#include<iostream>
using namespace std;
int main()
{
     int range1,range2,i,j,flag=0;
    cout<<"Enter a range:";
    cin>>range1;
    cin>>range2;
    cout<<"Pronic numbers between "<<range1<<" and "<<range2<<" are: ";
    for(i=range1;i<=range2;i++)
    {
    flag=0;
     for(j=0;j<=i;j++)
   {
       if(j*(j+1)==i)
       {
           flag=1;
           break;
       }
   }

   if(flag==1)
    cout<<i<<" ";
}
}

Input/Output:
Enter a range:10
200
Pronic numbers between 10 and 200 are: 12 20 30 42 56 72 90 110 132 156 182

Program in Java
  
Here is the source code of the Java Program to Find out all Pronic numbers present within a given range.

Code:

import java.util.Scanner;
public class FindPronicNumbersInRange {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
      int range1,range2;
      System.out.println("Enter a range:");
      range1=cs.nextInt();
      range2=cs.nextInt();
      System.out.println("Pronic numbers between "+range1+" and "+range2+" are: ");
      for(int i=range1;i<=range2;i++)
      {
          int flag=0;
         for(int j=0;j<=i;j++)
       {
           if(j*(j+1)==i)
           {
               flag=1;
               break;
           }
       }

     if(flag==1)
      System.out.print(i+" ");
      }
      cs.close();
}
}

Input/Output:
Enter a range:
120
350
Pronic numbers between 120 and 350 are: 
132 156 182 210 240 272 306 342 


Program in Python
  
Here is the source code of the Program to Find out all Pronic numbers present within a given range.

Code:

import math
print("Enter a range:")
range1=int(input())
range2=int(input())
print("Pronic numbers between ",range1," and ",range2," are: ")
for i in range(range1,range2+1):
    flag = 0
    for j in range(0, i + 1):
        if j * (j + 1) == i:
            flag = 1
            break
    if flag == 1:
        print(i,end=" ")

Input/Output:
Enter a range:
2000
2500
Pronic numbers between  2000  and  2500  are: 
2070 2162 2256 2352 2450

More:-

C/C++/Java/Python Practice Question 

Post a Comment

0 Comments