Abundant number in c

Abundant number

        A number is said to be abundant number if value of sum of all divisors of the given number is greater than the given number.

Eg

Given number = 12;
Divisors of given number(12) = 1, 2, 3, 4, 6.
Sum of the Divisors = 15
Sum value (15) > Given Number(12)
So the given number is known as abundant number.

Problem Statement

Write a c program to check whether the given number is an abundant number or not. 

Solution

#include<stdio.h>
int main()
{
    int n,i,sum=0;
    scanf("%d",&n);
    for(i=1;i<n;i++)
    {
        if(n%i==0)
        {
            sum=sum+i;
        }
    }
    if(sum>n)
    {
        printf("abundant number");
    }
    else
    printf("not a abundant number");
return 0;
}

Input
18     

Output                                                                                                                          
abundant number  

Program Explanation

  • In this c program, we will check the given number is an abundant number or not
  • Here stdio.h header file is declared for standard input and output functions.
  • Integer variables declared are n, i and sum.
  • Get the input value through scanf function.
  • In for loop check for divisors of given number and then add the divisors stored in sum variable.
  • using if else condition check the sum value with the input number in order to verify for abundant number or not.

  • If sum value greater than the input number then the given number is an abundant number.
  • Finally the output of the given number is displayed using printf function.

Abundant number program in c


Rajesh

This Blog will help you to find out the c programs solution easily and also you can able to understand the program.Please follow our blog for more useful updates.

Post a Comment (0)
Previous Post Next Post