Perfect number in c++




Perfect number code in c++


#include<iostream>
#include<iomanip>
int main(){
  int n,i=1,sum=0;

  cout<<"Enter a number: ";
  scanf("%d",&n);

  while(i<n){
         if(n%i==0)
               sum=sum+i;
              i++;
  }
  if(sum==n)
         cout << i  <<  " is a perfect number";
  else
         cout << i << " is not a perfect number";

  return 0;
}


Programs of c++


Post a Comment