WAP in qbasic to input a number and find whether it is a pronic / heteromecic number or not .
Answers
Answered by
0
Answer:
public class Main
{
static boolean isPronic(int n){
if(n==0){
return true;
}
for(int i = 1; i <= n; i++){
if(i*(i+1) == n){
return true;
}
}
return false;
}
public static void main(String[] args) {
System.out.print("Enter a number:");
java.util.Scanner sc = new java.util.Scanner(System.in);
int x = sc.nextInt();
if(isPronic(x)){
System.out.println(x + " is pronic");
}
else{
System.out.println(x + " is not pronic");
}
}
}
Explanation:
Similar questions