JAVA, Python, C++ and C programs for students. Here you will also find solutions to boards papers of ISC Computer Science Practical and CBSE Computer Science. ISC and ICSE JAVA PROGRAMS
Pronic Number || Program ICSE Class X
Write a program to input a positive number and check and print whether it is a Pronic number or not.
(Pronic number is a number which can be written as product of two consecutive integers)
Example:
12 = 3 x 4
42 = 6 x 7
20 = 4 x 5
ENTER A POSITIVE INTEGER:
classPronicNumber:
defpronicRepresentation(self):
print(self.__number," is a Pronic Number. ",self.__number," = ",self.__index," x ",(self.__index+1))
defisPronic(self):
i = 1
while (i*(i+1) <= self.__number):
if(i*(i+1) == self.__number):
self.__flag = True
self.__index = i
break
i +=1
return(self.__flag)
def__init__(self,n):
self.__number = n
__number = 0
__index = -1
__flag = False
n = int(input("Enter a positive integer."))
obj = PronicNumber(n)
if(obj.isPronic()):
obj.pronicRepresentation()
else:
print(n," is not a Pronic Number.")
importjava.util.Scanner;
publicclassICSEJava {
publicstaticvoidmain(String[] args) {
intn;
Scannerin = newScanner(System.in);
System.out.println("Enter a positive integer:");
n = in.nextInt();
PronicNumberobj = newPronicNumber(n);
if(obj.isPronic())
obj.pronicRepresentation();
else
System.out.println(n+" is not a Pronic Number");
in.close();
}
}
classPronicNumber {
publicvoidpronicRepresentation() {
System.out.println(number+" is a Pronic Number. "+number+" = "+index+" x "+(index+1));
No comments:
Post a Comment