Computer Science, asked by snehajosemay, 17 days ago

Write a program to determine whether the number n is equal to the sum of its proper positive divisor (excluding the number itself)​

Answers

Answered by waledkasa
0

Answer:

#include <iostream>

#include<bits/stdc++.h>

using namespace std;

int main()

{

int num;

cin>>num;

   // Final result of summation of divisors

   int result = 0;

   if(num == 1) // there will be no proper divisor

     return result;

   // find all divisors which divides 'num'

   for (int i=2; i<=sqrt(num); i++)

   {

       // if 'i' is divisor of 'num'

       if (num%i==0)

       {

           // if both divisors are same then add

           // it only once else add both

           if (i==(num/i))

               result += i;

           else

               result += (i + num/i);

       }

   }

   // Add 1 to the result as 1 is also a divisor

   return (result + 1);

}

Explanation:

C++

Similar questions