468,167 Members | 1,959 Online

# for loop

hello buddy.how r u? i cant able to write a program to print first k
prfect number. perfect number is the sum of all factor less than equal
to tht number n which is equal to tht number,for example 6 is perfect
number, and its factor is 1,2,3 and 1+2+3=6. try to help by tomm. bye
have a nice time.take care.

Sep 29 '05 #1
9 4887

"sej" <sw**********@yahoo.co.in> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
hello buddy.how r u? i cant able to write a program to print first k
prfect number. perfect number is the sum of all factor less than equal
to tht number n which is equal to tht number,for example 6 is perfect
number, and its factor is 1,2,3 and 1+2+3=6. try to help by tomm. bye
have a nice time.take care.

i m ok, thx. sugg: do ur own hmwrk. and spk englsh
Sep 29 '05 #2
sej wrote:
hello buddy.how r u? i cant able to write a program to print first k
prfect number. perfect number is the sum of all factor less than equal
to tht number n which is equal to tht number,for example 6 is perfect
number, and its factor is 1,2,3 and 1+2+3=6. try to help by tomm. bye
have a nice time.take care.

See this FAQ and the one following:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

Cheers! --M

Sep 29 '05 #3
sej wrote:
hello buddy.
I'm not your buddy.
how r u?
Pardon?
i cant able to write a program to print first k prfect number. perfect
number is the sum of all factor less than equal to tht number n which is
equal to tht number,for example 6 is perfect number, and its factor is
1,2,3 and 1+2+3=6. try to help by tomm. bye
have a nice time.take care.

So which part of that do you have problems with? Show us what you have so
far.

Sep 29 '05 #4
#include<iostream>
#include<conio.h>

int main()
{
int i=2;
int k=0;

while(k!=5) // say you want the first 5 perfect numbers
{
int sum=0;
for( int j=1;j<=i/2;j++)
{
if ((i%j)==0)
sum+=j;
}
if(sum==i)
{
cout<<"The number is perfect"<<sum<<endl;
k++;
}
i++;
} //
getch();
return 0;
}
Sep 29 '05 #5
Hey..sorry for the bad indendation. But it solves your purpose :)

zealot
Sep 29 '05 #6
sej wrote:
hello buddy.how r u? i cant able to write a program to print first k
prfect number. perfect number is the sum of all factor less than equal
to tht number n which is equal to tht number,for example 6 is perfect
number, and its factor is 1,2,3 and 1+2+3=6. try to help by tomm. bye
have a nice time.take care.

OK, well first you have to write a function which returns true if n is a
perect number and false otherwise.

bool is_a_perfect_number(int n)
{
...
}

and then you have to call it in a loop (maybe a for loop) so that you
call the function for successive integers.

Maybe you would need a few other functions such as, return true if a is
a factor of b.

bool is_a_factor(int a, int b)
{
...
}

Make sense so far? Well this is called programming, so have a go and if
you get stuck post your code back here.

john
Sep 29 '05 #7
Howard wrote:
"sej" <sw**********@yahoo.co.in> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
hello buddy.how r u? i cant able to write a program to print first k
prfect number. perfect number is the sum of all factor less than equal
to tht number n which is equal to tht number,for example 6 is perfect
number, and its factor is 1,2,3 and 1+2+3=6. try to help by tomm. bye
have a nice time.take care.

i m ok, thx. sugg: do ur own hmwrk. and spk englsh

His email address is from India.
--
Derek
Sep 30 '05 #8

"Derek Baker" <me@derekbaker.eclipse.co.uk> wrote in message
news:ad******************************@eclipse.net. uk...
Howard wrote:
"sej" <sw**********@yahoo.co.in> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
hello buddy.how r u? i cant able to write a program to print first k
prfect number. perfect number is the sum of all factor less than equal
to tht number n which is equal to tht number,for example 6 is perfect
number, and its factor is 1,2,3 and 1+2+3=6. try to help by tomm. bye
have a nice time.take care.

i m ok, thx. sugg: do ur own hmwrk. and spk englsh

His email address is from India.
--
Derek

So? I'm not commenting on poor grammar or poor spelling, but the use of
phrases like "how r u?", "tht" for "that", and no capitalization to start
sentences. Those are not factors of his being from India, they're IM-speak,
the shorthand that (mostly) kids are using on their text messagers, etc.,
and it's annoying. In a field such as programming, why use such shorthand?
You can't program in shorthand, and if you want to communicate with others,
it's best to be clear.

"At least that's my opinion... I could be wrong."

-Howard

Sep 30 '05 #9
Derek Baker wrote:
Howard wrote:
"sej" <sw**********@yahoo.co.in> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
hello buddy.how r u? i cant able to write a program to print first k
prfect number. perfect number is the sum of all factor less than equal
to tht number n which is equal to tht number,for example 6 is perfect
number, and its factor is 1,2,3 and 1+2+3=6. try to help by tomm. bye
have a nice time.take care.

i m ok, thx. sugg: do ur own hmwrk. and spk englsh

His email address is from India.
--
Derek

So, what is that supposed to mean ? I am also from India. Please shed
some light on the cryptic sentence of yours.

The original post has nothing to do with the location. The fault lies
in the fact that 'sej' has used the same language he would have been
using in his IM world to post to a newsgroup.

Sep 30 '05 #10

### This discussion thread is closed

Replies have been disabled for this discussion.

### Similar topics

 reply views Thread by Charles Alexander | last post: by 3 posts views Thread by Anand Pillai | last post: by 43 posts views Thread by Gremlin | last post: by 5 posts views Thread by Martin Schou | last post: by 32 posts views Thread by Toby Newman | last post: by 2 posts views Thread by Alex | last post: by 3 posts views Thread by Ben R. | last post: by 32 posts views Thread by cj | last post: by 16 posts views Thread by Claudio Grondi | last post: by 2 posts views Thread by ADezii | last post: by 1 post views Thread by sipeed | last post: by reply views Thread by LessComplexity | last post: by reply views Thread by ravipankaj | last post: by reply views Thread by ravipankaj | last post: by 1 post views Thread by gcdp | last post: by reply views Thread by kamranasdasdas | last post: by 14 posts views Thread by EricB | last post: by reply views Thread by gcreed | last post: by 2 posts views Thread by tgifrank32 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.