473,473 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 5567

"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 New Member
#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 New Member
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.