473,320 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

for loop

sej
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 5555

"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
zealot
8
#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
zealot
8
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Charles Alexander | last post by:
Hello I am new to php & MySQL - I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Sample_ID Marker_ID Variation ...
3
by: Anand Pillai | last post by:
This is for folks who are familiar with asynchronous event handling in Python using the asyncore module. If you have ever used the asyncore module, you will realize that it's event loop does not...
43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
5
by: Martin Schou | last post by:
Please ignore the extreme simplicity of the task :-) I'm new to C, which explains why I'm doing an exercise like this. In the following tripple nested loop: int digit1 = 1; int digit2 = 0;...
32
by: Toby Newman | last post by:
At the page: http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000 or http://tinyurl.com/4ptzs the author warns: "The for loop is frequently used, usually...
2
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled...
3
by: Ben R. | last post by:
In an article I was reading (http://www.ftponline.com/vsm/2005_06/magazine/columns/desktopdeveloper/), I read the following: "The ending condition of a VB.NET for loop is evaluated only once,...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
16
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of...
2
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.