Abundant Number in C Programming || Learning Duniya
What will be the programming for Abundant Number?
Today topic is Abundant Number. we will discuss about, what is Abundant Number, what are the examples of Abundant Number, and its programming stuff with program, logic, some output either number is Abundant Number or not.
What is Abundant Number?
Abundant Number are same as Perfect Number but there is slit difference, that a number is Abundant Number when it factor sum or divisor sum is greater then the number, means when we find factor or divisor then the sum of all divisor or factor except that number is greater then that number it is called Abundant Number.
Example:- Let us take a number 30 when we find its divisor we will get 1, 2, 3, 5, 6, 10, 15, 30. But we will not include 30, so sum is :-
1 + 2 + 3 + 5 + 6 + 10 + 15 = 42 which is greater then the original number, so 30 is Abundant Number.
Let take another number 29 when we will find its divisor we will get 1, 29, and we have to not include 29 so sum will be :- 1 which is not equal to the original number, so it is not Abundant Number.
Programming :-
#include<stdio.h>
#include<conio.h>
int main()
{
int num, i, newNum = 0; //Data type deceleration.
printf(" Enter the number to check either it is Abundant number or not");
scanf("%d",&num); //User input.
for(i=1; i<num; i++) //For finding divisor.
{
if(num%i==0) //Condition for divisor
{
newNum = newNum + i; //Adding divisor
}
}
if(newNum > num) //Comparing the new number to original Number.
{
printf(" %d is a Abundant Number ",num);
}
else
{
printf(" %d is not a Abundant Number ",num);
}
getch();
return 0;
}
Output:-
Fig:- 1
Fig:- 2
Logic:-
For Abundant Number we have to look at the logic of the Perfect Number, both have the same logic but difference is at only comparing the new number with the original number. We have to firstly find the divisor of the given number by using For loop and if else condition. After that we have to add all the number excluding the number itself, now we have to compare both number new number and original number and if new number is greater then the original number that that number is Abundant Number other wiser not.
If you face any problem then comment in comment section or visit on my YouTube Channel. You will find more logical video and all videos are in Hindi language.
Comments
Post a Comment