### Function Programming : Perfect Number in C

WAP using C-Function to check whether the given number is Perfect or Not.

#include<stdio.h>
int main()
{
int i;
scanf("%d",&i);
checkperfect(i);
}

int checkperfect(int j)
{
int a,sum=0;
for(a=1;a<=j/2;a++)
{
if (j%a = = 0)
sum+=a ;
}

if(sum = = j)
printf("\n Perfect Number \n");
else
printf("\n Not Perfect Number \n");
}

1. #include
int perfect_num(int a)
{
int i,sum=0;
for(i=1;i<a;i++)
{
if(a%i==0)
{
sum += i;
}
}
if(sum==a)return 1;
else return 0;
}

int main()
{
int n,ans;
printf("Given an input to find the perfect number: ");
scanf("%d",&n);
ans = perfect_num(n);
if(ans==1)printf("%d is a perfect number.\n", n);
else printf("%d is not a perfect number.\n", n);
return 0;
}

2. #include
#include
main()
{
int i;
scanf("%d",&i);
checkperfect(i);
}

int checkperfect(int j)
{
int a,sum=0;
for(a=1;a<=j/2;a++)
{
if(j%a==0)
sum+=a;
}
if(sum==j)
printf("\n Perfect Number \n");
else
printf("\n Not Perfect Number \n");
}

3. #include
#include
int perfect_check(int);
int main()
{
int n,sho;
printf("\n Enter number for check weathe it is perfect or not:");
scanf("%d",&n);
sho=perfect_check(n);
getch();
return 0;

}

int perfect_check(int sal)
{
int shu,sa=0;
for(shu=1;shu<sal;shu++)
{
if(sal%shu==0)
sa+=shu;
}
if(sa==sal)
printf("\n It is perfect number");
else
printf("\n It is not perfect number");
getch();
return shu;

}

4. #include
#include
int perfect_check(int);
int main()
{
int n,shohan;
printf("\n Enter number for check weathe it is perfect or not:");
scanf("%d",&n);
shohan=perfect_check(n);
getch();
return 0;

}

int perfect_check(int salmaan)
{
for(shuvo=1;shuvo<salmaan;shuvo++)
{
if(salmaan%shuvo==0)
}
printf("\n It is perfect number");
else
printf("\n It is not perfect number");
getch();
return shuvo;

}

5. #include
#include
int perfect_check(int);
int main()
{
int n,shohan;
printf("\n Enter number for check weathe it is perfect or not:");
scanf("%d",&n);
shohan=perfect_check(n);
getch();
return 0;

}

int perfect_check(int salmaan)
{
shuvo=1;
do
{
if(salmaan%shuvo==0)
shuvo++;
}while(shuvo<salmaan);

printf("\n It is perfect number");
else
printf("\n It is not perfect number");
getch();
return shuvo;

}

6. #include
#include
int perfect_check(int);
int main()
{
int n,shohan;
printf("\n Enter number for check weathe it is perfect or not:");
scanf("%d",&n);
shohan=perfect_check(n);
getch();
return 0;

}

int perfect_check(int salmaan)
{
shuvo=1;
while(shuvo<salmaan)
{
if(salmaan%shuvo==0)
shuvo++;
}

printf("\n It is perfect number");
else
printf("\n It is not perfect number");
getch();
return shuvo;

}

7. #include
int checkperfect(int n);
main()
{
int n;
printf("Enter the number for check wheather itis perfect or not:");
scanf("%d",&n);
checkperfect(n);
}

int checkperfect(int p)
{
int i,sum=0;
for(i=1;i<=p/2;i++)
{
if(p%i==0)
sum+=i;
}
if(sum==p)
printf("\n Perfect Number \n");
else
printf("\n Not Perfect Number \n");
}

8. #include
#include
int check_perfect(int);
int main()
{
int a,result;
printf("\n Enter number:");
scanf("%d",&a);
result=check_perfect(a);
}

int check_perfect(int n)
{
int i,k=0;
for(i=1;i<n;i++)
{
if(n%i==0)
k+=i;
}
if(k==n)
printf("\n %d is a perfect number:",n);
else
printf("\n %d is not a perfect number:",n);
return n;
}

9. #include
int main()
{
int n,i=1,sum;
printf("%/n Enter the number");
scanf("%d",& n);
while(i<n)
{
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
printf("/n%d is a perfect number",i);
else
printf("/n%d is non perfect number",i);
return 0;
}

10. #include
int main()
{
int n,i=1,sum=0;
printf("nEnter a number: ");
scanf("%d",&n);
while(i<n){
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
printf("n%d is a Perfect Number",i);
else
printf("n%d is Non Perfect Number",i);
return 0;
}

11. #include

int checkPerfect(int n)
{
int i,sum=0;
for(i=1; i<n; i++)
{
if(n%i==0)
{
sum += i;
}
}
return sum==n ? 1:0;
}

int main()
{
int n,result;
printf("Enter a number: ");
scanf("%d",&n);
result = checkPerfect(n);
if(result==1)
{
printf("%d is a perfect number.\n", n);
}
else
{
printf("%d is not a perfect number.\n", n);
}
return 0;
}

12. #include
int checkperfect(int n);
main()
{
int n;
printf("Enter the number for check wheather itis perfect or not:");
scanf("%d",&n);
checkperfect(n);
}

int checkperfect(int p)
{
int i,sum=0;
for(i=1;i<=p/2;i++)
{
if(p%i==0)
sum+=i;
}
if(sum==p)
printf("\n Perfect Number \n");
else
printf("\n Not Perfect Number \n");
}

13. #include
int main()
{
int num;
i=1;
sum=0;

printf("%/n Enter the number");
scanf("%d",& num);
while(i<num)
{
if(num%i==0)
sum=sum+i;
i++;
}

if(sum==num)
{
printf("/n%d is a perfect number",i);
}
else
{
printf("/n%d is non perfect number",i);
}

return 0;
}

14. #include
using namespace std;
main ()
{
int n,i=1,sum=0;
cout<<"enter n value:";
cin>>n;
do
{
if(n%i==0)
{
sum=sum+i;
}
i++;
}
while(i<n);
if(sum==n)
cout<<"PERFECT";
else
cout<<"NOT";
}

15. Id-201210803

#include
using namespace std;
int perfect(int a)
{
int sum=0;
for(int i=1;i>n;
int re= perfect(n);
if(re==n)
cout<<"\n\nYes!\n It Is A perfect number.\n\n";
else
cout<<"\n\nNo! \n It Is Not A Perfect Number.\n\n";
}

16. #include
using namespace std;
int checkperfect(int j);
main()
{
int i;
cin>>i;
checkperfect(i);
}

int checkperfect(int j)
{
int a,sum=0;
for(a=1;a<=j/2;a++)
{
if(j%a==0)
sum+=a;
}
if(sum==j)
cout<<"\n Perfect Number \n";
else
cout<<"\n Not Perfect Number \n";
}

17. #include
using namespace std;

class perfect
{
public:
int num,sum;
perfect();
void show();
~perfect();
};

perfect::perfect()
{
cout<<"Enter a number: ";
cin>>num;
}

void perfect::show()
{
int i;
sum=0;
for(i=1;i<=num/2;i++)
{
if(num%i==0)
sum=sum+i;
}
if(sum==num)
cout<<endl<<num<<" is a perfect number."<<endl;
else
cout<<endl<<num<<" is not a perfect number."<<endl;
}
perfect::~perfect()
{

}
main()
{
perfect ob1,ob2;
ob1.show();
ob2.show();
}

18. #include
using namespace std;
class perfect
{
public:
int num;
perfect();
void show();
~perfect();
};
perfect::perfect()
{
cout<<"Enter a number: ";
cin>>num;
cout<<endl;
}
void perfect:: show()
{
int i,sum=0;
for(i=1; i<=num/2; i++)
{
if(num%i==0)
sum=sum+i;
}
if(sum==num)
cout<<"Prefect number..."<<endl;
else
cout<<"Not perfect number..."<<endl;
}
perfect::~perfect()
{

}
int main()
{
perfect obj;
obj.show();
return 0;
}

19. #include
using namespace std;
class perfect
{
public:
int i,sum=0,n;
perfect();
void show();
~perfect()
{

}

};
perfect::perfect()
{
cout<<"Input Number to check perfect: ";
cin>>n;
}
void perfect::show()
{
for(i=1;i<n-1;i++)
if(n%i==0)
{
sum=sum+i;
}
if(n==sum)
cout<<"This is perfect Number."<<endl;
else
cout<<"This is Not perfect Number."<<endl;

}
int main()
{
perfect appel;
appel.show();
}

20. using C++

#include
using namespace std;

class cons
{
public:
int num;
cons(int i);
~cons();

void result();
};

cons::cons(int i)
{
num = i;
}

void cons::result()
{
int sum = 0;
for (int i = 1; i < num; i++){
if (num % i == 0)
sum += i;
}
if (sum == num)
cout << num << " is a perfect number --\n";
else
cout << num << " is not a perfect number --\n";
}
cons::~cons()
{
cout << "[+]MEMORY RELEASED[+]";
}

int main()
{
int i = 0;
cout << "Enter the number that you want to check --: ";
cin >> i;

cons obj(i);
obj.result();

return 0;
}

21. using constructor
mamun ur rashid
#include
int checkperfect(int j);
int main()
{
int i;
scanf("%d",&i);
checkperfect(i);
}

int checkperfect(int j)
{
int a,sum=0;
for(a=1;a<=j/2;a++)
{
if (j%a==0)
sum+=a ;
}

if(sum==j)
printf("\n Perfect Number \n");
else
printf("\n Not Perfect Number \n");
}

22. using constructor

#include
using namespace std;
class perfect
{
public:
int j, a,t=0;
perfect();

~perfect();
void result();
};
perfect::perfect()
{
cout<<"Enter a number :" ;
cin>>j;
}
perfect::~perfect()
{

}
void perfect::result()
{

for(a=1;a<=j/2;a++)
{
if(j%a==0)
t+=a;
}
if(t==j)
cout<<"This is perfect number:";
else
cout<<"This is not perfect number :"<<"\n";
}
int main()
{
perfect sb;
sb.result();
}

23. #include
using namespace std;
class perfect
{
public:
int num,i,sum=0;
perfect();
~perfect()
{
cout<<"Distructor active";
}
int func()
{
for(i=1;i>num;
}

int main()
{
perfect obj;
obj.func();
return 0;
}

id:201510660

24. #include
using namespace std;
class perfect
{
public:
int num,i,sum=0;
perfect();
~perfect()
{
cout<<"Distructor active";
}
int setu()
{
for(i=1;i>num;
}

int main()
{
perfect obj;
obj.setu();
return 0;
}

id:201510992