Computer Science, asked by Nitin1012, 10 months ago

Write a cpp program to find the Perfect numbers in the range
Write a program to find the perfect numbers between a given range.
Input Format:

The first input contains an integer which denotes the starting number of the range

The second input contains an integer which denotes the ending number of the range

Answers

Answered by rishavsharma21pd1prg
9

Answer:

#include <iostream>  

int main()

{

   int n,i=1,sum=0;

   cout << "Enter a number: ";

   cin >> n;

      while(i<n)

    {

      if(n%i==0)

      sum=sum+i;

      i++;  

     }

 

if(sum==n)

   cout << i << " is a perfect number\n";  

else

   cout << i << " is not a perfect number\n";  

return 0;

}

Answered by MSFLAB3
7

Answer:

#include<iostream>

main()

{

 int n1,n2,p=0;

 std::cin>>n1>>n2;

 for(int i=n1;i<=n2;i++)

 {

   for(int j=1;j<i;j++)

   {

     if(i%j==0)

       p+=j;

     else

       p+=0;

   }

   if(p==i)

   {

     std::cout<<p<<" ";

     p*=0;

   }

   else

     p*=0;

 }

}

       

Similar questions