Current location: Hot Scripts Forums » Programming Languages » C/C++ » Perfect number...


Perfect number...

Reply
  #1 (permalink)  
Old 07-11-05, 04:19 PM
Argo_Jeude Argo_Jeude is offline
New Member
 
Join Date: Jul 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Perfect number...

Does anyone knows why this isn't working?
I got a problem where I must make a program in C++ which finds the percet number between 2 and number m(which user enters).
Anyway,I made the program to see if the number you entered is perfect number but I can't make it so that it calculates which number between 2 and m is the perfect.
Sorry my english is not so good.
Note:The perfect number is number which is equal to the sum of his (dividive numbers?)
I'm sorry I don't know how to write it in english,but here is example:
28=1+2+4+7+14
Number 28 can be divided by number 1,2,4,7,14.Sum of that dividing is 28.
Here's the number which checks is the entered number(only one number)perfect:
*********************
#include<iostream.h>
void main(){
int x,suma=0,number;
cout<<"Please insert number which will be checked if it is a perfect\n"; cout<<"number:\n";
cin>>broj;
for(int i=2;i<=number;i++){
if(broj%i==0){
suma=suma+(number/i);
}
}
if(suma==number)cout<<number;
cin>>x; //so that the program doesn't close
return;
}

********************************
And here is the program that isn't working somehow...:
*******************************
#include<iostream.h>
void main(){
int m,x,suma=0;
cout<<"Please enter number m:\n";
cin>>m;
for(int i=2;i<=m;i++){
for(int j=2;j<=i;j++){
if(i%j==0)
suma=suma+(i/j);
}
if(suma==i)
cout<<i<<endl;
}
cin>>x; //so that the program doesn't close
return;
}
***********************************
What do you think?
Please tell me,I'm very interested in this problem,and I've been smashing my head for so long...
Reply With Quote
  #2 (permalink)  
Old 07-14-05, 02:35 PM
harzem harzem is offline
Newbie Coder
 
Join Date: Jun 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
You are forgetting suma=0 for all loops inside. suma is getting greater and greater.
after the first "for(i=2;i.....), insert a suma=0;
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Number Formatting Y3000 PHP 6 11-13-04 08:30 AM
add a number every 30 minutes Dion PHP 5 08-31-04 12:52 AM
Add sequential number to database from checkbox ajndede ASP 1 05-04-04 07:43 AM


All times are GMT -5. The time now is 04:34 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.