CSharp  Java  Python  Swift  GO  WPF  Ruby  Scala  F#  JavaScript  SQL  PHP  Angular  HTML
Program to print all Pronic numbers between 1 and 100ExplanationIn this program, we need to display all Pronic numbers between 1 and 100. Pronic number The pronic number can be defined as the number which is a product of two consecutive numbers. Mathematically, the Pronic number can be represented as N x (N + 1) To find whether a number n is a Pronic number or not, use for loop to iterate from i = 1 to i = n and check whether i*(i+1) is equal to n for any value of i. Some of the examples of Pronic numbers are 6 = 2 x 3 72 = 8 x 9 Algorithm
SolutionPython#isPronicNumber() will determine whether a given number is a pronic number or not def isPronicNumber(num): flag = False; for j in range(1, num+1): #Checks for pronic number by multiplying consecutive numbers if((j*(j+1)) == num): flag = True; break; return flag; #Displays pronic numbers between 1 and 100 print("Pronic numbers between 1 and 100: "); for i in range(1, 101): if(isPronicNumber(i)): print(i), print(" "), Output: Pronic numbers between 1 and 100: 2 6 12 20 30 42 56 72 90 C#include <stdio.h> #include <stdbool.h> //isPronicNumber() will determine whether a given number is pronic number or not bool isPronicNumber(int num){ bool flag = false; for(int j = 1; j <= num; j++){ //Checks for pronic number by multiplying consecutive numbers if((j*(j+1)) == num){ flag = true; break; } } return flag; } int main() { //Displays pronic numbers between 1 and 100 printf("Pronic numbers between 1 and 100: \n"); for(int i = 1; i <= 100; i++){ if(isPronicNumber(i)) printf("%d ", i); } return 0; } Output: Pronic numbers between 1 and 100: 2 6 12 20 30 42 56 72 90 JAVApublic class PronicNumbers { //isPronicNumber() will determine whether a given number is pronic number or not public static boolean isPronicNumber(int num){ boolean flag = false; for(int j = 1; j <= num; j++){ //Checks for pronic number by multiplying consecutive numbers if((j*(j+1)) == num){ flag = true; break; } } return flag; } public static void main(String[] args) { //Displays pronic numbers between 1 and 100 System.out.println("Pronic numbers between 1 and 100: "); for(int i = 1; i <= 100; i++){ if(isPronicNumber(i)) System.out.print(i + " "); } } } Output: Pronic numbers between 1 and 100: 2 6 12 20 30 42 56 72 90 C#using System; public class PronicNumbers { //isPronicNumber() will determine whether a given number is pronic number or not public static Boolean isPronicNumber(int num){ Boolean flag = false; for(int j = 1; j <= num; j++){ //Checks for pronic number by multiplying consecutive numbers if((j*(j+1)) == num){ flag = true; break; } } return flag; } public static void Main() { //Displays pronic numbers between 1 and 100 Console.WriteLine("Pronic numbers between 1 and 100: "); for(int i = 1; i <= 100; i++){ if(isPronicNumber(i)) Console.Write(i + " "); } } } Output: Pronic numbers between 1 and 100: 2 6 12 20 30 42 56 72 90 PHP<!DOCTYPE html> <html> <body> <?php //isPronicNumber() will determine whether a given number is pronic number or not function isPronicNumber($num){ $flag = false; for($j = 1; $j <= $num; $j++){ //Checks for pronic number by multiplying consecutive numbers if(($j*($j+1)) == $num){ $flag = true; break; } } return $flag; } //Displays pronic numbers between 1 and 100 print("Pronic numbers between 1 and 100: <br>"); for($i = 1; $i <= 100; $i++){ if(isPronicNumber($i)) print($i . " "); } ?> </body> </html> Output: Pronic numbers between 1 and 100: 2 6 12 20 30 42 56 72 90
Next Topic#
