Program in C++ to check a given number is perfect or not Using function
#include<iostream> #include<conio.h> using namespace std; int isPerfect(int n); int main() { int a,p=0; cout<<"Enter a number:-"; cin>>a; p=isPerfect(a); if(p==a) cout<<a<<" is perfect no."; 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