adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C++ to check a given number is perfect or not Using function

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:-






Post a Comment

0 Comments