Computer Applications
An abundant number is a number for which the sum of its proper divisors (excluding the number itself) is greater than the original number. Write a program to input number and check whether it is an abundant number or not.
Sample input: 12
Sample output: It is an abundant number.
Explanation: Its proper divisors are 1, 2, 3, 4 and 6
Sum = 1 + 2 + 3 + 4 + 6 = 16
Hence, 12 is an abundant number.
Java
Java Iterative Stmts
9 Likes
Answer
import java.util.Scanner;
public class KboatAbundantNumber
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the number: ");
int n = in.nextInt();
int sum = 0;
for (int i = 1; i < n; i++) {
if (n % i == 0)
sum += i;
}
if (sum > n)
System.out.println(n + " is an abundant number.");
else
System.out.println(n + " is not an abundant number.");
}
}
Variable Description Table
Program Explanation
Output
Answered By
5 Likes
Related Questions
Write a program to accept a number and check whether it is a 'Spy Number' or not. (A number is spy if the sum of its digits equals the product of its digits.)
Example: Sample Input: 1124
Sum of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1*1*2*4 = 8A special two-digit number is such that when the sum of its digits is added to the product of its digits, the result is equal to the original two-digit number.
Example: Consider the number 59.
Sum of digits = 5 + 9 = 14
Product of digits = 5 * 9 = 45
Sum of the sum of digits and product of digits = 14 + 45 = 59Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits. If the value is equal to the number input, then display the message "Special two—digit number" otherwise, display the message "Not a special two-digit number".
A computerised bus charges fare from each of its passengers based on the distance travelled as per the tariff given below:
Distance (in km) Charges First 5 km ₹80 Next 10 km ₹10/km More than 15 km ₹8/km As the passenger enters the bus, the computer prompts 'Enter distance you intend to travel'. On entering the distance, it prints his ticket and the control goes back for the next passenger. At the end of journey, the computer prints the following:
- the number of passenger travelled
- total fare received
Write a program to perform the above task.
[Hint: Perform the task based on user controlled loop]Write a program to input a number and check whether it is a Harshad Number or not. [A number is said to be Harshad number, if it is divisible by the sum of its digits. The program displays the message accordingly.]
For example;
Sample Input: 132
Sum of digits = 6 and 132 is divisible by 6.
Output: It is a Harshad Number.
Sample Input: 353
Output: It is not a Harshad Number.