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 2,4,7,14,28.Sum of that dividing is 28.
Here's the number which checks is the entered number(only one
number)perfect:
*********************
********************************Code:#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...:
*******************************
***********************************Code:#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...



LinkBack URL
About LinkBacks




I used to be an adventurer like you... then I took an arrow to the knee.