Abundant numer is a number which the sum of it dividers is bigger
then the divider itself.
12 : 1+2+3+4+6=16>12
I need to build a program which gets a number input.
It prints all the numbers bellow it which could be written as the sum of two
abundant numbers and present its sum.
If there is more then one combination for the sum,we need to print the sum with the smallest number for all the sums .
for example if i enter 54:
There are two possible abbondant number sum 54=12+42 =18+36
The program will print only
54=12+42
I have built a program and who prints only the pairs of the number
but it shows -1 -1 as if on all the range the is no such numbers
??
Code:
#include <stdio.h>
void main(){
int num;
int index,tndex,kndex,jndex;
int flag_1,flag_2;
int sum;
int smallest,smallest_ever,smallest_ever_2;
sum=0;
flag_1=0;
flag_2=0;
smallest=-1;
smallest_ever=-1;
smallest_ever_2=-1;
printf("enter number\n");
scanf("%d",&num);
for(index=0;index<num;index++){ //start for main number
for(tndex=0;tndex<index;tndex++){//start for first num
for(kndex=0;kndex<index;kndex++){//start for second num
if (tndex+kndex==index){ //start sum check
for(jndex=1;jndex<tndex;jndex++){//start abbondence check for first num
if (tndex%jndex==0){
sum=sum+jndex;
}
}//end abbondence check for first num
if (tndex<sum){
flag_1=1;
}
sum=0;
for(jndex=1;jndex<kndex;jndex++){//start abbondence check for first num
if (kndex%jndex==0){
sum=sum+jndex;
}
}//end abbondence check for first num
if (kndex<sum){
flag_2=1;
}
if ((flag_2==1)&&(flag_1==1)){ //start flag check
if (kndex>=tndex){
smallest=tndex;
if (smallest<=smallest_ever){
smallest_ever=smallest;
smallest_ever_2=kndex;
}
}
else
{
smallest=kndex;
if (smallest<=smallest_ever){
smallest_ever=smallest;
smallest_ever_2=tndex;
}
}
}//end flag check
} //end sum check
}//end for second num
}//end for first num
printf("%d %d",smallest_ever,smallest_ever_2);
}//end for main number
}//end main