Program in C++ to find the perfect number between 1 to Nth Using function
#include<iostream> #include<conio.h> using namespace std; int isPerfect(int n); int main() { int a,p; cout<<"Enter a number:-"; cin>>a; for(int j=1;j<=a;j++) { p=isPerfect(j); if(p==j) cout<<j<<" is perfect no.\n"; //else // cout<<a<<" is not perfect no."; } } int isPerfect(int n) { int sum=0,i; for(i=1;i<n;i++) { if(n%i==0) { sum+=i; } } return (sum); }Output:-
0 Comments