What is a perfect number?
"Perfect number is a positive number which sum of all positive divisors excluding that number."
For example 6 is Perfect Number since divisor of 6 are 1, 2 and 3. Sum of its divisor is
1 + 2+ 3 =6
and 28 is also a Perfect Number
since 1+ 2 + 4 + 7 + 14= 28
Other perfect numbers: 496, 8128
- #include<iostream.h>
- #include<conio.h>
- void main() //Start of main
- {
- clrscr();
- int i=1, u=1, sum=0;
- while(i<=500)
- { // start of first loop.
- while(u<=500)
- { //start of second loop.
- if(u<i)
- {
- if(i%u==0 )
- sum=sum+u;
- } //End of if statement
- u++;
- } //End of second loop
- if(sum==i)
- {
- cout<<i<<" is a perfect number."<<"\n";
- }
- i++;
- u=1; sum=0;
- } //End of First loop
- getch();
- } //End of main
6 is a perfect number.
28 is a perfect number.
496 is a perfect number.
Note:
If you want to calculate perfect number within your desire limit simply take a variable and replaced 500 with it.
In APL: isPerfect←{⍵=+/(⍳⍵-1){(0=⍺|⍵)/⍺}⍵}
ReplyDeleteisPerfect 28
1
Also...
ReplyDelete{⍵ if isPerfect ¨⍵}⍳500
6 28 496
Thanks friend. Great help
ReplyDeleteWelcome Kepler Manuel.
Deletegood
ReplyDeletevery nice.was a great support for me!!!!!
ReplyDeleteThanks. And Keep Visiting..
DeleteAM NEW DUDE. SO WHERE DO I START?
ReplyDeleteYou Need To Understand The Basics Of C++ Programming.
DeleteTry To Practice As Much As You Can.
Practice is Very Important For Your Solid Base to Learn Programming.. Good Luck
Fahad bhai: i am new where do i start ?
ReplyDeleteWaqas Bhai.
DeleteYou Need To Understand The Basics Of C++ Programming.
Try To Practice As Much As You Can.
Practice is Very Important For Your Solid Base to Learn Programming.. Good Luck
#include
ReplyDeleteusing namespace std;
int main()
{
int num,perfect;
int per=0;
cout<<"enter number \n";
cin>>num;
int newnum=num;
for(int i=1;i<=num;i++){
if(num%i == 0){
perfect=i;
cout<<perfect<<endl;
per=per+perfect;
}
}
if(newnum == per/2){
cout<<"perfect";
}else{
cout<<"not perfect";
}
}
This comment has been removed by the author.
ReplyDeleteA.o.A Fahad ..
ReplyDeleteYour website is really really helping. I am a beginner in C++.I have made a more simplest logic for perfect numbers and it works.
#include
#include
using namespace std;
int main()
{
int a,b,c;
c=0;
cout<<"Plz enter a number :";
cin>>b;
for(a=1;a<b;a++)
{
if(b%a==0)
c=c+a;
}
if(c==b)
cout<<"Yes it is a Perfect number";
else
cout<<"No it is not a perfect number";
getch();
}
what is using namespace std
Deletethis doesn't work for 6
Deletewhat is if and if else statement
ReplyDeleteconditions..
DeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
DeleteHow To Use C++ In Windows7? Becoz in my system windows7 there are not operating c Language & C++ Plz Help...
ReplyDeleteYou can use codeblocks or turbo c++
DeleteAll the programs are really helpful... but i need more guidance bcuz every time i try to write program, i literally get confused! PLZ HELP ME GET OUT OF IT BCUZ I AM DOING SOFTWARE ENGG! I REALLY NEED HELP
ReplyDelete
ReplyDeleteThanks for sharing the very useful info about clanguage and please keep updating........
hi
ReplyDeleteI am a student of class 7and cant understand this.
please can anyone help me with correcting the following:
@include<
#include
void Main()
{
Clrscr();
Int a=7;
char section = F;
cout>>”Hello class”<<a;
cout<<”\nSection: “<<section<<endline;
getch()
}