C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Program to print all abundant numbers between 1 and 100The abundant number can be called an excessive number and defined as the number for which the sum of its proper divisors is greater than the number itself. A first abundant number is the integer 12 having the sum (16) of its proper divisors (1,2,3,4,6) which is greater than itself(12). Examples: 12, 18, 20, 24, 30, 36 In this program, we have to find all abundant numbers between 1 and 100. Algorithm
Java Programpublic class Abundant_number_1to100 { public static void main(String[] args) { int n, i, j, sum = 0; n =100; for (i = 1; i <= n; i++) { for (j = 1; j <= i/2; j++) { if (i % j == 0) { sum = sum + j; } } if (sum > i) System.out.print( i+" "); sum = 0; } } } Output: 12 18 20 24 30 36 40 42 48 54 56 60 66 70 72 78 80 84 88 90 96 100 C Program#include <stdio.h> int main () { int n, i, j, sum = 0; n=100; for (i = 1; i <= n; i++) { for (j = 1; j <= i/2; j++) { if (i % j == 0) { sum = sum + j; } } if (sum > i) printf("%d ", i); sum = 0; } printf("\n"); return 0; } Output: 12 18 20 24 30 36 40 42 48 54 56 60 66 70 72 78 80 84 88 90 96 100 Python Programn = 101 su = 0 for i in range(1, n): for j in range(1, int(i)): if (i % j == 0): su = su + j if (su > i): print( i) su = 0 Output: 12 18 20 24 30 36 40 42 48 54 56 60 66 70 72 78 80 84 88 90 96 100 PHP Program<?php $n = 100; $su = 0; for($i = 1;$i<=$n;$i++) { for($j=1; $j<=$i/2;$j++) { if ($i % $j == 0){ $su = $su + $j; } } if ($su > $i) { echo $i,"��"; } $su = 0; } ?> Output: 12 18 20 24 30 36 40 42 48 54 56 60 66 70 72 78 80 84 88 90 96 100 C# programusing System; public class Abundant { public static void Main() { int n = 100, i ,j; int su = 0; for(i = 1;i<=n;i++) { for(j=1; j<=i/2;j++) { if (i % j == 0){ su = su + j; } } if (su > i) { Console.Write(i+" "); } su = 0; } } } Output: 12 18 20 24 30 36 40 42 48 54 56 60 66 70 72 78 80 84 88 90 96 100
Next Topic#
|