473,383 Members | 1,862 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,383 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 5564

"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...
1
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.