Developer side
1: Declare variables that are going to be used in program.
2: start a while loop from 1 to 1000
3: In each iteration send the number (counter of loop 'n') to the function
isperfect' to check if the number is perfect or not.
4: In the function 'isperfect' start a while loop from 1 to less than the counter of above while loop 'n'.
5: Now check if the modulus of both the counters is equal to zero . If condition stands true add the value of variable 'i' to a variable named sum (that is initially zero).
6: Increase the counter by one and while loop ends here.
7: Now outside the loop check if the sum is equal to 'n' then this is perfect otherwise not.
8: Return the control back to main and program ends here.
Developer side
1: Declare variables that are going to be used in program.
2: start a while loop from 1 to 1000
3: In each iteration send the number (counter of loop 'n') to the function
isperfect' to check if the number is perfect or not.
4: In the function 'isperfect' start a while loop from 1 to less than the counter of above while loop 'n'.
5: Now check if the modulus of both the counters is equal to zero . If condition stands true add the value of variable 'i' to a variable named sum (that is initially zero).
6: Increase the counter by one and while loop ends here.
7: Now outside the loop check if the sum is equal to 'n' then this is perfect otherwise not.
8: Return the control back to main and program ends here.
Code:
#include<iostream>
#include<iomanip>
using namespace std;
void
isperfect(int);
int
main()
{ int
n=1,i=1,sum=0;
while(n<=1000)
{ isperfect(n);
n++;
}I
system("pause");
return 0;
}
void
isperfect(int n)
{int i=1,sum=0;
while(i<n){
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
cout << i <<
" is a perfect number"<<endl;
}
Comments
Post a Comment