Program to Find Nth Abundant Number

A Number is an Abundant Number if it's less than the sum of its proper divisors.

Example:
               18 divisors are 1, 2, 3, 6, 9, 18
                  sum of divisors=1+2+3+6+9+18=39
                   18<39
                    Number < sum of divisors
                             
Problem statement:-  Program to Find Nth Abundant Number.

Data requirement:-

   Input Data:- rangenumber

   Output Data:- rangenumber, letest

   Additional Data:- cnum, num1, sum, rem, rem2, rev

Program in C

Here is the source code of the C Program to Find Nth Abundant Number.

Code:

#include <stdio.h>
int
main ()
{
  int i, rangenumber, num = 1, c = 0, letest = 0;
  printf ("Enter the Nth value:");
  scanf ("%d", &rangenumber);

  while (c != rangenumber)
    {
      int num1=num;
       int sum=0;
       for(i=1;i<num1;i++)
    {
        if(num1%i==0)
        {
            sum=sum+i;
        }
    }
     if(sum>num)
      {
          c++;
          letest=num;
      }
      num = num + 1;
    }
  printf ("%dth Abundant number is %d", rangenumber, letest);
  return 0;
}

Input/Output:
Enter the Nth value:5
5th Abundant number is 30

Program in C++

Here is the source code of the C++ Program to Find Nth Abundant Number.

Code:

#include <iostream>
using namespace std;
int
main ()
{
  int i, rangenumber, num = 1, c = 0, letest = 0;
  cout<<"Enter the Nth value:";
  cin>>rangenumber;

  while (c != rangenumber)
    {
      int num1=num;
       int sum=0;
       for(i=1;i<num1;i++)
    {
        if(num1%i==0)
        {
            sum=sum+i;
        }
    }
     if(sum>num)
      {
          c++;
          letest=num;
      }
      num = num + 1;
    }
  cout<<rangenumber<<"th Abundant number is "<<letest;
  return 0;
}

Input/Output:
Enter the Nth value:7
7th Abundant number is 40

Program in Java
  
Here is the source code of the Java Program to Find Nth Abundant Number.

Code:

import java.util.Scanner;
public class NthAbundantNumber {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int  rangenumber, num = 1, c = 0, letest = 0,i;
  System.out.println("Enter Nth number:");
  rangenumber=cs.nextInt();

  while (c != rangenumber)
    {
      int num1=num;
       int sum=0;
       for(i=1;i<num1;i++)
       {
        if(num1%i==0)
        {
            sum=sum+i;
        }
    }
     if(sum>num)
      {
          c++;
          letest=num;
      }
      num = num + 1;
    }
System.out.println(rangenumber+"th Abundant Square number is "+letest);
cs.close();
}
}

Input/Output:
Enter Nth number:
8
8th Abundant Square number is 42

Program in Python
  
Here is the source code of the Python Program to Find Nth Abundant Number.

Code:

rangenumber=int(input("Enter a Nth Number:"))
c = 0
letest = 0
num = 1
while c != rangenumber:
    num1 = num
    sum = 0
    for i in range(1, num1):
        if num1 % i == 0:
            sum = sum + i
    if sum>num:
        c+=1
        letest = num

    num = num + 1
print(rangenumber,"th Abundant number is ",letest)

Input/Output:
Enter a Nth Number:20
20 th Abundant number is  90


More:-

C/C++/Java/Python Practice Question 

Post a Comment

0 Comments