Here 3+2+1=3*2*1=6. It means 321 is a perfect number.
#include<iostream> using namespace std; int main() { int n,r,m=1,s=0; cout<<"Enter value of n:"; cin>>n; while(n>0) { r=n%10; n=n/10; m=m*r; s=s+r; } if(s==m) cout<<"\nNumber is a perfect number."; else cout<<"\nNumber is not a perfect number."; system("pause"); return 0; }Output:
Enter value of n:123 Number is a perfect number.
No comments:
Post a Comment